Example usage for com.amazonaws.services.securitytoken.model AssumeRoleWithWebIdentityResult getCredentials

List of usage examples for com.amazonaws.services.securitytoken.model AssumeRoleWithWebIdentityResult getCredentials

Introduction

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

Prototype


public Credentials getCredentials() 

Source Link

Document

The temporary security credentials, which include an access key ID, a secret access key, and a security token.

Usage

From source file:io.fineo.client.auth.CognitoCredentialsProvider.java

License:Open Source License

/**
 * Gets the session credentials by requesting an OpenId Connect token from
 * Amazon Cognito and then trading it with AWS Secure Token Service for the
 * short lived session credentials.//from   w  w w  . ja v  a2 s .  com
 */
private void populateCredentialsWithSts(String token) {

    boolean isAuthenticated = identityProvider.isAuthenticated();
    String roleArn = (isAuthenticated) ? authRoleArn : unauthRoleArn;

    AssumeRoleWithWebIdentityRequest sessionTokenRequest = new AssumeRoleWithWebIdentityRequest()
            .withWebIdentityToken(token).withRoleArn(roleArn).withRoleSessionName("ProviderSession")
            .withDurationSeconds(sessionDuration);
    appendUserAgent(sessionTokenRequest, getUserAgent());
    AssumeRoleWithWebIdentityResult sessionTokenResult = securityTokenService
            .assumeRoleWithWebIdentity(sessionTokenRequest);
    Credentials stsCredentials = sessionTokenResult.getCredentials();

    sessionCredentials = new BasicSessionCredentials(stsCredentials.getAccessKeyId(),
            stsCredentials.getSecretAccessKey(), stsCredentials.getSessionToken());
    sessionCredentialsExpiration = stsCredentials.getExpiration();

}