use of com.amazonaws.auth.AWSCredentialsProvider in project photon-model by vmware.
the class AWSUtils method getArnSessionCredentialsAsync.
/**
* Authenticates and returns a DeferredResult set of session credentials for a valid ARN that
* authorizes this system's account ID (validated through
* {@link #AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY} and
* {@link #AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY}) and the externalId parameter.
*
* If the system properties are unset, then this call will automatically fail.
*
* @param arn The Amazon Resource Name to validate.
* @param externalId The external ID this ARN has authorized.
* @param region The region to validate within.
* @param executorService The executor service to issue the request.
*/
public static DeferredResult<Credentials> getArnSessionCredentialsAsync(String arn, String externalId, String region, ExecutorService executorService) {
AWSCredentialsProvider serviceAwsCredentials;
try {
serviceAwsCredentials = new AWSStaticCredentialsProvider(new BasicAWSCredentials(AWS_MASTER_ACCOUNT_ACCESS_KEY, AWS_MASTER_ACCOUNT_SECRET_KEY));
} catch (Throwable t) {
return DeferredResult.failed(t);
}
AWSSecurityTokenServiceAsync awsSecurityTokenServiceAsync = AWSSecurityTokenServiceAsyncClientBuilder.standard().withRegion(region).withCredentials(serviceAwsCredentials).withExecutorFactory(() -> executorService).build();
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(arn).withRoleSessionName(UUID.randomUUID().toString()).withDurationSeconds(getArnSessionDurationSeconds()).withExternalId(externalId);
DeferredResult<AssumeRoleResult> r = new DeferredResult<>();
OperationContext operationContext = OperationContext.getOperationContext();
awsSecurityTokenServiceAsync.assumeRoleAsync(assumeRoleRequest, new AsyncHandler<AssumeRoleRequest, AssumeRoleResult>() {
@Override
public void onSuccess(AssumeRoleRequest request, AssumeRoleResult result) {
OperationContext.restoreOperationContext(operationContext);
r.complete(result);
}
@Override
public void onError(Exception ex) {
OperationContext.restoreOperationContext(operationContext);
r.fail(ex);
}
});
return r.thenApply(AssumeRoleResult::getCredentials);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project iep by Netflix.
the class AwsClientFactoryTest method createCredentialsProviderOverride.
@Test
public void createCredentialsProviderOverride() throws Exception {
AwsClientFactory factory = new AwsClientFactory(config);
AWSCredentialsProvider creds = factory.createCredentialsProvider("ec2-test", null);
Assert.assertTrue(creds instanceof STSAssumeRoleSessionCredentialsProvider);
Assert.assertEquals("arn:aws:iam::1234567890:role/IepTest", getField(creds, "roleArn"));
Assert.assertEquals("iep", getField(creds, "roleSessionName"));
}
use of com.amazonaws.auth.AWSCredentialsProvider in project iep by Netflix.
the class AwsClientFactoryTest method createCredentialsProviderForAccount.
@Test
public void createCredentialsProviderForAccount() throws Exception {
AwsClientFactory factory = new AwsClientFactory(config);
AWSCredentialsProvider creds = factory.createCredentialsProvider("ec2-account", "123");
Assert.assertTrue(creds instanceof STSAssumeRoleSessionCredentialsProvider);
Assert.assertEquals("arn:aws:iam::123:role/IepTest", getField(creds, "roleArn"));
Assert.assertEquals("iep", getField(creds, "roleSessionName"));
}
use of com.amazonaws.auth.AWSCredentialsProvider in project iep by Netflix.
the class AwsClientFactoryTest method createCredentialsProviderForAccountIgnored.
@Test
public void createCredentialsProviderForAccountIgnored() throws Exception {
AwsClientFactory factory = new AwsClientFactory(config);
AWSCredentialsProvider creds = factory.createCredentialsProvider("ec2-test", "123");
Assert.assertTrue(creds instanceof STSAssumeRoleSessionCredentialsProvider);
Assert.assertEquals("arn:aws:iam::1234567890:role/IepTest", getField(creds, "roleArn"));
Assert.assertEquals("iep", getField(creds, "roleSessionName"));
}
use of com.amazonaws.auth.AWSCredentialsProvider in project iep by Netflix.
the class AwsClientFactoryTest method createCredentialsProvider.
@Test
public void createCredentialsProvider() {
AwsClientFactory factory = new AwsClientFactory(config);
AWSCredentialsProvider creds = factory.createCredentialsProvider(null, null);
Assert.assertTrue(creds instanceof DefaultAWSCredentialsProviderChain);
}
Aggregations