Java Code Examples for com.aliyuncs.sts.model.v20150401.AssumeRoleRequest#setPolicy()
The following examples show how to use
com.aliyuncs.sts.model.v20150401.AssumeRoleRequest#setPolicy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OSSUtil.java From xnx3 with Apache License 2.0 | 6 votes |
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret,String roleArn, String roleSessionName, String policy,ProtocolType protocolType) throws ClientException { try { // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求 IClientProfile profile = DefaultProfile.getProfile(region_cn_hangzhou, accessKeyId, accessKeySecret); DefaultAcsClient client = new DefaultAcsClient(profile); // 创建一个 AssumeRoleRequest 并设置请求参数 final AssumeRoleRequest request = new AssumeRoleRequest(); request.setVersion(sta_api_version); request.setMethod(MethodType.POST); request.setProtocol(protocolType); request.setRoleArn(roleArn); request.setRoleSessionName(roleSessionName); request.setPolicy(policy); // 发起请求,并得到response final AssumeRoleResponse response = client.getAcsResponse(request); return response; } catch (ClientException e) { throw e; } }
Example 2
Source File: STSServiceImpl.java From jframe with Apache License 2.0 | 6 votes |
AssumeRoleResponse assumeRole(String id, String roleArn, String roleSessionName, String policy, ProtocolType protocolType) throws ServerException, com.aliyuncs.exceptions.ClientException { DefaultAcsClient client = clients.get(id); // 创建一个 AssumeRoleRequest 并设置请求参数 final AssumeRoleRequest request = new AssumeRoleRequest(); request.setVersion(_config.getConf(id, K_api_version)); request.setMethod(MethodType.POST); request.setProtocol(protocolType); request.setRoleArn(roleArn); request.setRoleSessionName(roleSessionName); request.setPolicy(policy); request.setDurationSeconds(Long.parseLong(_config.getConf(id, K_durationSeconds, "3600"))); // 默认值为3600 // 发起请求,并得到response final AssumeRoleResponse response = client.getAcsResponse(request); // client.shutdown(); return response; }
Example 3
Source File: StsServiceSample.java From jframe with Apache License 2.0 | 6 votes |
static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret, String roleArn, String roleSessionName, String policy, ProtocolType protocolType) throws ClientException { try { // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求 IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret); DefaultAcsClient client = new DefaultAcsClient(profile); // 创建一个 AssumeRoleRequest 并设置请求参数 final AssumeRoleRequest request = new AssumeRoleRequest(); request.setVersion(STS_API_VERSION); request.setMethod(MethodType.POST); request.setProtocol(protocolType); request.setRoleArn(roleArn); request.setRoleSessionName(roleSessionName); request.setPolicy(policy); // 发起请求,并得到response final AssumeRoleResponse response = client.getAcsResponse(request); return response; } catch (ClientException e) { throw e; } }
Example 4
Source File: FunctionComputeClientTest.java From fc-java-sdk with MIT License | 5 votes |
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(STS_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(); }