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);
}
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();
}
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"));
}
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;
}
}
}
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();
}
Aggregations