Search in sources :

Example 6 with BasicSessionCredentials

use of com.amazonaws.auth.BasicSessionCredentials in project beam by apache.

the class AwsModuleTest method testAWSStaticCredentialsProviderSerializationDeserialization.

@Test
public void testAWSStaticCredentialsProviderSerializationDeserialization() throws Exception {
    String awsKeyId = "key-id";
    String awsSecretKey = "secret-key";
    AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsKeyId, awsSecretKey));
    String serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    AWSCredentialsProvider deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    assertEquals(credentialsProvider.getCredentials().getAWSAccessKeyId(), deserializedCredentialsProvider.getCredentials().getAWSAccessKeyId());
    assertEquals(credentialsProvider.getCredentials().getAWSSecretKey(), deserializedCredentialsProvider.getCredentials().getAWSSecretKey());
    String sessionToken = "session-token";
    BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(awsKeyId, awsSecretKey, sessionToken);
    credentialsProvider = new AWSStaticCredentialsProvider(sessionCredentials);
    serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    BasicSessionCredentials deserializedCredentials = (BasicSessionCredentials) deserializedCredentialsProvider.getCredentials();
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    assertEquals(deserializedCredentials.getAWSAccessKeyId(), awsKeyId);
    assertEquals(deserializedCredentials.getAWSSecretKey(), awsSecretKey);
    assertEquals(deserializedCredentials.getSessionToken(), sessionToken);
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 7 with BasicSessionCredentials

use of com.amazonaws.auth.BasicSessionCredentials in project SimianArmy by Netflix.

the class STSAssumeRoleSessionCredentialsProvider method startSession.

/**
 * Starts a new session by sending a request to the AWS Security Token
 * Service (STS) to assume a Role using the long lived AWS credentials. This
 * class then vends the short lived session credentials for the assumed Role
 * sent back from STS.
 */
private void startSession() {
    AssumeRoleResult assumeRoleResult = securityTokenService.assumeRole(new AssumeRoleRequest().withRoleArn(roleArn).withDurationSeconds(DEFAULT_DURATION_SECONDS).withRoleSessionName("SimianArmy"));
    Credentials stsCredentials = assumeRoleResult.getCredentials();
    sessionCredentials = new BasicSessionCredentials(stsCredentials.getAccessKeyId(), stsCredentials.getSecretAccessKey(), stsCredentials.getSessionToken());
    sessionCredentialsExpiration = stsCredentials.getExpiration();
}
Also used : AssumeRoleRequest(com.amazonaws.services.securitytoken.model.AssumeRoleRequest) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AssumeRoleResult(com.amazonaws.services.securitytoken.model.AssumeRoleResult) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Credentials(com.amazonaws.services.securitytoken.model.Credentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials)

Example 8 with BasicSessionCredentials

use of com.amazonaws.auth.BasicSessionCredentials in project crate by crate.

the class S3ClientSettingsTests method testCredentialsTypeWithAccessKeyAndSecretKeyAndSessionToken.

@Test
public void testCredentialsTypeWithAccessKeyAndSecretKeyAndSessionToken() {
    final S3ClientSettings settings = S3ClientSettings.getClientSettings(Settings.builder().put("access_key", "access_key").put("secret_key", "secret_key").put("session_token", "session_token").build());
    BasicSessionCredentials credentials = (BasicSessionCredentials) settings.credentials;
    assertThat(credentials.getAWSAccessKeyId(), is("access_key"));
    assertThat(credentials.getAWSSecretKey(), is("secret_key"));
    assertThat(credentials.getSessionToken(), is("session_token"));
}
Also used : BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) Test(org.junit.Test)

Example 9 with BasicSessionCredentials

use of com.amazonaws.auth.BasicSessionCredentials in project athenz by yahoo.

the class AWSCredentialsProviderImpl method refresh.

@Override
public void refresh() {
    try {
        AWSTemporaryCredentials creds = ztsClient.getAWSTemporaryCredentials(domainName, roleName, externalId, minExpiryTime, maxExpiryTime);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Refresh: Credentials with id: {} and expiration {} were fetched", creds.getAccessKeyId(), creds.getExpiration());
        }
        awsCredsTimestamp = creds.getExpiration();
        this.credentials = new BasicSessionCredentials(creds.getAccessKeyId(), creds.getSecretAccessKey(), creds.getSessionToken());
    } catch (Exception ex) {
        if (awsCredsTimestamp != null && awsCredsTimestamp.millis() <= System.currentTimeMillis()) {
            awsCredsTimestamp = null;
            credentials = null;
        }
        // if we have no credentials then we'll throw an exception
        // otherwise we'll just log it
        LOG.error("Refresh: Failed to get the AWS temporary credentials from ZTS", ex);
        if (credentials == null) {
            throw ex;
        }
    }
}
Also used : BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) IOException(java.io.IOException)

Example 10 with BasicSessionCredentials

use of com.amazonaws.auth.BasicSessionCredentials in project athenz by yahoo.

the class InstanceAWSProvider method getInstanceClient.

AWSSecurityTokenService getInstanceClient(AWSAttestationData info) {
    String access = info.getAccess();
    if (access == null || access.isEmpty()) {
        LOGGER.error("getInstanceClient: No access key id available in instance document");
        return null;
    }
    String secret = info.getSecret();
    if (secret == null || secret.isEmpty()) {
        LOGGER.error("getInstanceClient: No secret access key available in instance document");
        return null;
    }
    String token = info.getToken();
    if (token == null || token.isEmpty()) {
        LOGGER.error("getInstanceClient: No token available in instance document");
        return null;
    }
    BasicSessionCredentials creds = new BasicSessionCredentials(access, secret, token);
    return AWSSecurityTokenServiceClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).withRegion(Regions.fromName(awsRegion)).build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials)

Aggregations

BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)28 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)9 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)8 Credentials (com.amazonaws.services.securitytoken.model.Credentials)6 AWSCredentials (com.amazonaws.auth.AWSCredentials)5 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)5 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)5 Test (org.junit.Test)5 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)4 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 ClientConfiguration (com.amazonaws.ClientConfiguration)3 SdkClientException (com.amazonaws.SdkClientException)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)2 IOException (java.io.IOException)2 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)1