本文整理汇总了Java中com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.assumeRole方法的典型用法代码示例。如果您正苦于以下问题:Java AWSSecurityTokenServiceClient.assumeRole方法的具体用法?Java AWSSecurityTokenServiceClient.assumeRole怎么用?Java AWSSecurityTokenServiceClient.assumeRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient
的用法示例。
在下文中一共展示了AWSSecurityTokenServiceClient.assumeRole方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientForAccount
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; //导入方法依赖的package包/类
private AmazonEC2Client getClientForAccount(final String accountId, final Region region) {
final AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());
final AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(
"arn:aws:iam::ACCOUNT_ID:role/fullstop-role")
.withDurationSeconds(3600).withRoleSessionName(
"fullstop-role");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
final BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
assumeResult.getCredentials()
.getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
final AmazonEC2Client amazonEC2Client = new AmazonEC2Client(temporaryCredentials);
amazonEC2Client.setRegion(region);
return amazonEC2Client;
}
示例2: assumeRoleAndGetCredentials
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; //导入方法依赖的package包/类
private void assumeRoleAndGetCredentials() {
int defaultRequestedExpiryTimeInMinutes = jets3tProperties.getIntProperty("aws.session-credentials.expiry-time.to-be-requested", 60);
com.amazonaws.auth.AWSCredentials awsCredentials = new BasicAWSCredentials(iamAccessKey, iamSecretKey);
AWSSecurityTokenServiceClient stsClient =
new AWSSecurityTokenServiceClient(awsCredentials);
AssumeRoleRequest assumeRequest = new AssumeRoleRequest()
.withRoleArn(roleToBeAssumed)
.withDurationSeconds(defaultRequestedExpiryTimeInMinutes * 60)
.withRoleSessionName(DEFAULT_SESSION_NAME);
if(externalId != null) {
assumeRequest = assumeRequest.withExternalId(externalId);
}
AssumeRoleResult assumeResult =
stsClient.assumeRole(assumeRequest);
this.accessKey = assumeResult.getCredentials().getAccessKeyId();
this.secretKey = assumeResult.getCredentials().getSecretAccessKey();
this.sessionToken = assumeResult.getCredentials().getSessionToken();
this.expirationDate = assumeResult.getCredentials().getExpiration();
}
示例3: assumeAWSRole
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; //导入方法依赖的package包/类
public AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal) {
if (!awsEnabled) {
throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR,
"AWS Support not enabled");
}
AssumeRoleRequest req = getAssumeRoleRequest(account, roleName, principal);
AWSTemporaryCredentials tempCreds = null;
try {
AWSSecurityTokenServiceClient client = getTokenServiceClient();
AssumeRoleResult res = client.assumeRole(req);
Credentials awsCreds = res.getCredentials();
tempCreds = new AWSTemporaryCredentials()
.setAccessKeyId(awsCreds.getAccessKeyId())
.setSecretAccessKey(awsCreds.getSecretAccessKey())
.setSessionToken(awsCreds.getSessionToken())
.setExpiration(Timestamp.fromMillis(awsCreds.getExpiration().getTime()));
} catch (Exception ex) {
LOGGER.error("CloudStore: assumeAWSRole - unable to assume role: " + ex.getMessage());
return null;
}
return tempCreds;
}
示例4: getCredentials
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; //导入方法依赖的package包/类
private static AWSCredentials getCredentials(String iamRole, String externalId) {
if (isEmpty(iamRole)) return null;
AWSSecurityTokenServiceClient sts = new AWSSecurityTokenServiceClient();
int credsDuration = (int) (AWSCodeDeployPublisher.DEFAULT_TIMEOUT_SECONDS
* AWSCodeDeployPublisher.DEFAULT_POLLING_FREQUENCY_SECONDS);
if (credsDuration > 3600) {
credsDuration = 3600;
}
AssumeRoleResult assumeRoleResult = sts.assumeRole(new AssumeRoleRequest()
.withRoleArn(iamRole)
.withExternalId(externalId)
.withDurationSeconds(credsDuration)
.withRoleSessionName(AWSCodeDeployPublisher.ROLE_SESSION_NAME)
);
Credentials stsCredentials = assumeRoleResult.getCredentials();
BasicSessionCredentials credentials = new BasicSessionCredentials(
stsCredentials.getAccessKeyId(),
stsCredentials.getSecretAccessKey(),
stsCredentials.getSessionToken()
);
return credentials;
}
示例5: retrieveSessionCredentials
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; //导入方法依赖的package包/类
public BasicSessionCredentials retrieveSessionCredentials(AwsCredentialView awsCredential) {
LOGGER.debug("retrieving session credential");
AWSSecurityTokenServiceClient client = awsSecurityTokenServiceClient();
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest()
.withDurationSeconds(DEFAULT_SESSION_CREDENTIALS_DURATION)
.withExternalId(externalId)
.withRoleArn(awsCredential.getRoleArn())
.withRoleSessionName("hadoop-provisioning");
AssumeRoleResult result = client.assumeRole(assumeRoleRequest);
return new BasicSessionCredentials(
result.getCredentials().getAccessKeyId(),
result.getCredentials().getSecretAccessKey(),
result.getCredentials().getSessionToken());
}
示例6: assumeRole
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient; //导入方法依赖的package包/类
@Override
public AssumeRoleResult assumeRole(AWSSecurityTokenServiceClient awsSecurityTokenServiceClient, AssumeRoleRequest assumeRoleRequest)
{
return awsSecurityTokenServiceClient.assumeRole(assumeRoleRequest);
}