use of com.aliyuncs.sts.model.v20150401.AssumeRoleResponse in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method getAssumeRoleCredentials.
private Credentials getAssumeRoleCredentials(String policy) throws com.aliyuncs.exceptions.ClientException {
IClientProfile profile = DefaultProfile.getProfile(REGION, ACCESS_KEY, SECRET_KEY);
//DefaultProfile.addEndpoint("sts.us-west-1.aliyuncs.com", "us-west-1", "Sts", "sts.us-west-1.aliyuncs.com");
DefaultAcsClient client = new DefaultAcsClient(profile);
AssumeRoleRequest request = new AssumeRoleRequest();
request.setVersion(STS_API_VERSION);
request.setMethod(MethodType.POST);
request.setProtocol(ProtocolType.HTTPS);
request.setRoleArn(ROLE);
request.setRoleSessionName("test-session");
if (policy != null) {
request.setPolicy(policy);
}
AssumeRoleResponse stsResponse;
try {
stsResponse = client.getAcsResponse(request);
} catch (com.aliyuncs.exceptions.ClientException e) {
throw new RuntimeException(e);
}
String accessKey = stsResponse.getCredentials().getAccessKeyId();
String secretKey = stsResponse.getCredentials().getAccessKeySecret();
String stsToken = stsResponse.getCredentials().getSecurityToken();
assertNotNull(accessKey);
assertNotNull(secretKey);
assertNotNull(stsToken);
return stsResponse.getCredentials();
}
Aggregations