Search in sources :

Example 1 with DefaultAcsClient

use of com.aliyuncs.DefaultAcsClient 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();
}
Also used : AssumeRoleRequest(com.aliyuncs.sts.model.v20150401.AssumeRoleRequest) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) AssumeRoleResponse(com.aliyuncs.sts.model.v20150401.AssumeRoleResponse) IClientProfile(com.aliyuncs.profile.IClientProfile)

Example 2 with DefaultAcsClient

use of com.aliyuncs.DefaultAcsClient in project paascloud-master by paascloud.

the class AliyunSmsConfiguration method acsClient.

/**
 * Acs client acs client.
 *
 * @return the acs client
 *
 * @throws ClientException the client exception
 */
@Bean
public IAcsClient acsClient() throws ClientException {
    log.info("SMS Bean IAcsClient Start");
    IClientProfile profile = DefaultProfile.getProfile(paascloudProperties.getAliyun().getSms().getRegionId(), paascloudProperties.getAliyun().getKey().getAccessKeyId(), paascloudProperties.getAliyun().getKey().getAccessKeySecret());
    DefaultProfile.addEndpoint(paascloudProperties.getAliyun().getSms().getEndpointName(), paascloudProperties.getAliyun().getSms().getRegionId(), paascloudProperties.getAliyun().getSms().getProduct(), paascloudProperties.getAliyun().getSms().getDomain());
    DefaultAcsClient defaultAcsClient = new DefaultAcsClient(profile);
    log.info("加载SMS Bean IAcsClient OK");
    return defaultAcsClient;
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultAcsClient (com.aliyuncs.DefaultAcsClient)2 IClientProfile (com.aliyuncs.profile.IClientProfile)2 AssumeRoleRequest (com.aliyuncs.sts.model.v20150401.AssumeRoleRequest)1 AssumeRoleResponse (com.aliyuncs.sts.model.v20150401.AssumeRoleResponse)1 Bean (org.springframework.context.annotation.Bean)1