Example usage for com.amazonaws.services.securitytoken.model AssumeRoleRequest withExternalId

List of usage examples for com.amazonaws.services.securitytoken.model AssumeRoleRequest withExternalId

Introduction

In this page you can find the example usage for com.amazonaws.services.securitytoken.model AssumeRoleRequest withExternalId.

Prototype


public AssumeRoleRequest withExternalId(String externalId) 

Source Link

Document

A unique identifier that might be required when you assume a role in another account.

Usage

From source file:org.jets3t.service.security.AWSRoleSessionCredentials.java

License:Apache License

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);
    }//w w  w. ja v a2  s. c  o m
    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();
}