You can embed a URL in your development or tooling platform to provide logon-free access to the Data Management (DMS) console. This lets users directly access the DMS console and its features without signing in with an Alibaba Cloud account or as a RAM user. This topic describes how to create a URL for logon-free access.
Procedure
-
Create a RAM role to access DMS and grant it permissions. Then, create a RAM user and grant the
AliyunSTSAssumeRoleAccesspermission to the user. For more information, see Prerequisites. -
Obtain temporary credentials by assuming the role. These credentials—an AccessKey ID, AccessKey Secret, and a security token—are used to obtain a
SigninToken. For more information, see Step 1: Obtain temporary credentials. -
Obtain a
SigninToken, which is required to create the logon-free access URL. For more information, see Step 2: Obtain a SigninToken. -
Create the logon-free access URL. For more information, see Step 3: Create the logon-free access URL.
Prerequisites
If you meet all the following prerequisites, you can proceed to Step 1.
-
Create a RAM role to access DMS. For more information, see Create a RAM role for a trusted Alibaba Cloud account.
-
Grant permissions to the RAM role. For more information, see Grant permissions to a RAM role.
-
Create a RAM user. For more information, see Create a RAM user.
-
Grant the
AliyunSTSAssumeRoleAccesspermission to the RAM user. For more information, see Grant permissions to a RAM user.
Step 1: Obtain temporary credentials
Call the AssumeRole operation to obtain temporary credentials by assuming a RAM role. For more information about the AssumeRole operation, see AssumeRole.
The following Java code provides an example:
/**
* Obtains temporary credentials by calling the AssumeRole operation.
*/
private static AssumeRoleResponse.AssumeRoleResponseBodyCredentials assumeRole(
String accountId, String accessKeyId,
String accessKeySecret, String ramRoleArn) throws Exception {
// Configure the STS client.
Config config = new Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret)
// Note: The endpoint for Security Token Service (STS) is globally fixed. The sts.cn-hangzhou.aliyuncs.com endpoint is typically used.
.setEndpoint("sts.cn-hangzhou.aliyuncs.com");
Client client = new Client(config);
AssumeRoleRequest request = new AssumeRoleRequest();
// An ARN (Alibaba Cloud Resource Name) is a global resource identifier that specifies a RAM role.
request.setRoleArn(ramRoleArn);
// A custom parameter to distinguish between different tokens. This parameter can be used for user-level access auditing. Format: ^[a-zA-Z0-9\.@\-_]+$
request.setRoleSessionName("session-name");
request.setDurationSeconds(3600L); // Explicitly set the validity period in seconds.
RuntimeOptions runtime = new RuntimeOptions();
AssumeRoleResponse response = client.assumeRoleWithOptions(request, runtime);
return response.getBody().getCredentials();
}
Step 2: Obtain a SigninToken
Call the GetSigninToken operation to obtain a SigninToken.
The following Java code provides an example:
/**
* Obtains a SigninToken by using a security token.
*
* @param accesskeyId
* @param accessKeySecret
* @param securityToken
* @return
* @throws IOException
* @throws URISyntaxException
*/
private static String getSignInToken(String accesskeyId, String accessKeySecret, String securityToken)
throws IOException, URISyntaxException {
URIBuilder builder = new URIBuilder("http://signin.aliyun.com/federation");
builder.setParameter("Action", "GetSigninToken")
.setParameter("AccessKeyId", accesskeyId)
.setParameter("AccessKeySecret", accessKeySecret)
.setParameter("SecurityToken", securityToken)
.setParameter("TicketType", "normal");
HttpGet request = new HttpGet(builder.build());
CloseableHttpClient httpclient = HttpClients.createDefault();
try (CloseableHttpResponse response = httpclient.execute(request)) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String context = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = JSON.parseObject(context);
return jsonObject.getString("SigninToken");
} else {
System.out.println(response.getStatusLine());
}
}
return null;
}
Step 3: Create the logon-free access URL
Each SigninToken is single-use. To create another logon-free access URL, you must obtain a new token.
The following Java code provides an example:
Request example:
private static String getDmsLoginUrl(String pageUrl, String signInToken) throws URISyntaxException {
URIBuilder builder = new URIBuilder("http://signin.aliyun.com/federation");
builder.setParameter("Action", "Login");
// The URL to which the user is redirected when the session expires. This is typically a URL on your web server that is configured for a 302 redirect.
builder.setParameter("LoginUrl", "https://signin.aliyun.com/login.htm");
// The DMS page that the user accesses.
builder.setParameter("Destination", pageUrl);
builder.setParameter("SigninToken", signInToken);
HttpGet request = new HttpGet(builder.build());
return request.getURI().toString();
}
Response example:
Expiration: 2020-11-30T06:16:20Z
Access Key Id: STS.NT7L6Jp5Y8W9LNvGQku2x****
Access Key Secret: 4nU8F6rv8MCDR8tygMDnXvN9yCNBCVrxnqArj1n1****
Security Token: CAIS/gF1q6Ft5B2yfSjIr5e****+nep4j5XSTmjHo1E+eb1Ujo7xijz2IH9IeXhpB****/43nWlU7PkYlrloRoReREvCKM1565kSqFn6O11Qf****+5qsoasPETOITyZtZagToeUZdfZfejXGDKgvyRvwLz****/Vli+S/OggoJmadJlNWvRL0AxZrFsKxBltdUROF****+pKWSKuGfLC1dysQcO4gEWq4bHm5zAs0OH1QOhlrVP+N+qfqLJNZc8YM1NNP6ux/Fze6b71ypd1gNH7q8ejtYfpmua74jBXgUAuU3faraOrYd1SwZ9Z7knH****/n6ifBjpvw9Hlk0R9OcVhqAAXpZx****+STGa8vctRwyTWdMM5LByes3cr1D46jaj0****/lTMkoXCwjMlCs7sc+DA9xjJCcl57eKC7A3ThnJAWQyyeKZfIGgeHN7yUS5ND8r7TBn6bMUqwvfVX****/cbkzBX6iV6jrataHZPZdtQYHH6GgvQ5XZUZJjoD****
Your SigninToken is: 06ec409b9d8c48f6ac5dcd18a0513ee1dhUkhcRn5CMsDqffC4wxsuFt9xjYtYePmYTHEWSMVKLFyXXnSq3IUbon1v46wCmKPwrAejDvw2i8rilolPSuxpKRDxz****
Your PageUrl is : http://signin.aliyun.com/federation?Action=Login&LoginUrl=https%3A%2F%2Fsignin.aliyun.com%2Flogin.htm&Destination=https%3A%2F%2Fdms.aliyun.com&SigninToken=06ec409b9d8c48f6ac5dcd18a0513ee1dhUkhcRn5CMsDqffC4wxsuFt9xjYtYePmYTHEWSMVKLFyXXnSq3IUbon1v46wCmKPwrAejDvw2i8rilolPSuxpKRDxzD****
The following example shows the format of the logon-free access URL (PageUrl):
http://signin.aliyun.com/federation?Action=Login
&LoginUrl=<your-redirect-url-on-expiration>
&Destination=<your-target-dms-url>
&SigninToken=<your-signin-token>
The DMS page URL for the Destination parameter depends on the TicketType value.
-
If the value is
normal, the corresponding DMS domain ishttp://dms.aliyun.com. -
If the value is
mini, it is typically used for BID virtual operators. The corresponding domain ishttp://dms-ent4service.aliyun.com.
Next steps
Open the logon-free access URL (PageUrl) to access the DMS console. Once logged on, the user identity appears in the upper-right corner of the DMS console in the format {RAM role name}/{RoleSessionName}, for example, aliyunlogintest/session-name-123.