use of com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient in project athenz by yahoo.
the class InstanceAWSProviderTest method testVerifyInstanceIdentityARNMismatch.
@Test
public void testVerifyInstanceIdentityARNMismatch() {
MockInstanceAWSProvider provider = new MockInstanceAWSProvider();
provider.setIdentitySuper(true);
AWSSecurityTokenServiceClient mockClient = Mockito.mock(AWSSecurityTokenServiceClient.class);
GetCallerIdentityResult result = Mockito.mock(GetCallerIdentityResult.class);
Mockito.when(result.getArn()).thenReturn("arn:aws:sts::1235:assumed-role/athenz.service/athenz.service");
Mockito.when(mockClient.getCallerIdentity(ArgumentMatchers.any())).thenReturn(result);
provider.setStsClient(mockClient);
AWSAttestationData info = new AWSAttestationData();
info.setRole("athenz.service");
assertFalse(provider.verifyInstanceIdentity(info, "1234"));
}
use of com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient in project athenz by yahoo.
the class MockCloudStore method getTokenServiceClient.
@Override
public AWSSecurityTokenServiceClient getTokenServiceClient() {
if (exceptionStatusCode != 0) {
if (amazonException) {
AmazonServiceException ex = new AmazonServiceException("Error");
ex.setStatusCode(exceptionStatusCode);
throw ex;
} else {
throw new IllegalArgumentException("Error");
}
} else {
AWSSecurityTokenServiceClient client = Mockito.mock(AWSSecurityTokenServiceClient.class);
Mockito.when(client.assumeRole(Mockito.any(AssumeRoleRequest.class))).thenReturn(assumeRoleResult);
Mockito.when(client.getCallerIdentity(Mockito.any(GetCallerIdentityRequest.class))).thenReturn(callerIdentityResult);
return client;
}
}
use of com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient in project athenz by yahoo.
the class CloudStore method assumeAWSRole.
public AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal) {
if (!awsEnabled) {
throw new ResourceException(ResourceException.INTERNAL_SERVER_ERROR, "AWS Support not enabled");
}
AssumeRoleRequest req = getAssumeRoleRequest(account, roleName, principal);
AWSTemporaryCredentials tempCreds = null;
try {
AWSSecurityTokenServiceClient client = getTokenServiceClient();
AssumeRoleResult res = client.assumeRole(req);
Credentials awsCreds = res.getCredentials();
tempCreds = new AWSTemporaryCredentials().setAccessKeyId(awsCreds.getAccessKeyId()).setSecretAccessKey(awsCreds.getSecretAccessKey()).setSessionToken(awsCreds.getSessionToken()).setExpiration(Timestamp.fromMillis(awsCreds.getExpiration().getTime()));
} catch (Exception ex) {
LOGGER.error("CloudStore: assumeAWSRole - unable to assume role: " + ex.getMessage());
return null;
}
return tempCreds;
}
use of com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient in project cloudbreak by hortonworks.
the class AwsSessionCredentialClient method awsSecurityTokenServiceClient.
private AWSSecurityTokenServiceClient awsSecurityTokenServiceClient() {
if (!awsEnvironmentVariableChecker.isAwsAccessKeyAvailable() || !awsEnvironmentVariableChecker.isAwsSecretAccessKeyAvailable()) {
InstanceProfileCredentialsProvider instanceProfileCredentialsProvider = new InstanceProfileCredentialsProvider();
LOGGER.info("AWSSecurityTokenServiceClient will use aws metadata because environment variables are undefined");
return new AWSSecurityTokenServiceClient(instanceProfileCredentialsProvider);
} else {
LOGGER.info("AWSSecurityTokenServiceClient will use environment variables");
return new AWSSecurityTokenServiceClient();
}
}
use of com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient in project ice by Netflix.
the class AwsUtils method init.
/**
* This method must be called before all methods can be used.
* @param credentialsProvider
*/
public static void init(AWSCredentialsProvider credentialsProvider) {
awsCredentialsProvider = credentialsProvider;
clientConfig = new ClientConfiguration();
String proxyHost = System.getProperty("https.proxyHost");
String proxyPort = System.getProperty("https.proxyPort");
if (proxyHost != null && proxyPort != null) {
clientConfig.setProxyHost(proxyHost);
clientConfig.setProxyPort(Integer.parseInt(proxyPort));
}
s3Client = new AmazonS3Client(awsCredentialsProvider, clientConfig);
securityClient = new AWSSecurityTokenServiceClient(awsCredentialsProvider, clientConfig);
if (System.getProperty("EC2_REGION") != null && !"us-east-1".equals(System.getProperty("EC2_REGION"))) {
if ("global".equals(System.getProperty("EC2_REGION"))) {
s3Client.setEndpoint("s3.amazonaws.com");
} else {
s3Client.setEndpoint("s3-" + System.getProperty("EC2_REGION") + ".amazonaws.com");
}
}
}
Aggregations