Example usage for com.amazonaws.auth AWSSessionCredentials getSessionToken

List of usage examples for com.amazonaws.auth AWSSessionCredentials getSessionToken

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSSessionCredentials getSessionToken.

Prototype

public String getSessionToken();

Source Link

Document

Returns the session token for this session.

Usage

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

License:Open Source License

/**
 * Save the credentials to SharedPreferences
 *//* w  w w . ja v  a2  s . co m*/
private void saveCredentials(AWSSessionCredentials sessionCredentials, long time) {
    LOG.debug(TAG, "Saving credentials to SharedPreferences");
    if (sessionCredentials != null) {
        cache.put(namespace(AK_KEY), sessionCredentials.getAWSAccessKeyId());
        cache.put(namespace(SK_KEY), sessionCredentials.getAWSSecretKey());
        cache.put(namespace(ST_KEY), sessionCredentials.getSessionToken());
        cache.put(namespace(EXP_KEY), Long.toString(time));
    }
}

From source file:org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider.java

License:Apache License

/**
 * Get the username and password to use for the given uri.
 * @see org.eclipse.jgit.transport.CredentialsProvider#get(org.eclipse.jgit.transport.URIish, org.eclipse.jgit.transport.CredentialItem[])
 *///from  w w  w .  j a  v  a2 s . co m
@Override
public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
    String codeCommitPassword;
    String awsAccessKey;
    String awsSecretKey;
    try {
        AWSCredentials awsCredentials = retrieveAwsCredentials();
        StringBuilder awsKey = new StringBuilder();
        awsKey.append(awsCredentials.getAWSAccessKeyId());
        awsSecretKey = awsCredentials.getAWSSecretKey();
        if (awsCredentials instanceof AWSSessionCredentials) {
            AWSSessionCredentials sessionCreds = (AWSSessionCredentials) awsCredentials;
            if (sessionCreds.getSessionToken() != null) {
                awsKey.append('%').append(sessionCreds.getSessionToken());
            }
        }
        awsAccessKey = awsKey.toString();
    } catch (Throwable t) {
        logger.warn("Unable to retrieve AWS Credentials", t);
        return false;
    }
    try {
        codeCommitPassword = calculateCodeCommitPassword(uri, awsSecretKey);
    } catch (Throwable t) {
        logger.warn("Error calculating the AWS CodeCommit password", t);
        return false;
    }

    for (CredentialItem i : items) {
        if (i instanceof CredentialItem.Username) {
            ((CredentialItem.Username) i).setValue(awsAccessKey);
            logger.trace("Returning username " + awsAccessKey);
            continue;
        }
        if (i instanceof CredentialItem.Password) {
            ((CredentialItem.Password) i).setValue(codeCommitPassword.toCharArray());
            logger.trace("Returning password " + codeCommitPassword);
            continue;
        }
        if (i instanceof CredentialItem.StringType && i.getPromptText().equals("Password: ")) { //$NON-NLS-1$
            ((CredentialItem.StringType) i).setValue(codeCommitPassword);
            logger.trace("Returning password string " + codeCommitPassword);
            continue;
        }
        throw new UnsupportedCredentialItem(uri, i.getClass().getName() + ":" + i.getPromptText()); //$NON-NLS-1$
    }

    return true;
}