use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cloud-pipeline by epam.
the class S3TemporaryCredentials method generate.
@Override
public AbstractTemporaryCredentials generate(List<DataStorageAction> actions) {
String policy = createPolicyWithPermissions(actions);
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withDurationSeconds(getDuration()).withPolicy(policy).withRoleSessionName(sessionName).withRoleArn(getRole());
AWSSecurityTokenServiceClientBuilder builder = AWSSecurityTokenServiceClientBuilder.standard();
builder.setRegion(getAwsRegionId());
builder.setCredentials(DefaultAWSCredentialsProviderChain.getInstance());
AssumeRoleResult assumeRoleResult = builder.build().assumeRole(assumeRoleRequest);
Credentials resultingCredentials = assumeRoleResult.getCredentials();
setAccessKey(resultingCredentials.getSecretAccessKey());
setKeyId(resultingCredentials.getAccessKeyId());
setToken(resultingCredentials.getSessionToken());
setExpirationTime(expirationTimeWithUTC(resultingCredentials.getExpiration()));
setRegion(getAwsRegionId());
return this;
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project singleton by vmware.
the class S3Client method getRoleCredentials.
private synchronized Credentials getRoleCredentials() {
AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.getAccessKey(), config.getSecretkey()));
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withCredentials(awsCredentialsProvider).withRegion(config.getS3Region()).build();
AssumeRoleRequest arreq = new AssumeRoleRequest();
arreq.setDurationSeconds(DURATIONSEC);
arreq.setRoleArn(config.getRoleArn());
arreq.setRoleSessionName("SingletonRoleSession");
AssumeRoleResult sessionTokenResult = stsClient.assumeRole(arreq);
long time = System.currentTimeMillis();
Credentials result = sessionTokenResult.getCredentials();
reducedTime = (result.getExpiration().getTime() - (DURATIONSEC * 1000) - time) + TIME_ERR_RANGE;
return result;
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project athenz by AthenZ.
the class ZTSClient method getAssumeRoleRequest.
AssumeRoleRequest getAssumeRoleRequest(String account, String roleName) {
// assume the target role to get the credentials for the client
// aws format is arn:aws:iam::<account-id>:role/<role-name>
final String arn = "arn:aws:iam::" + account + ":role/" + roleName;
AssumeRoleRequest req = new AssumeRoleRequest();
req.setRoleArn(arn);
req.setRoleSessionName(roleName);
return req;
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method isCertificateCreated.
public static boolean isCertificateCreated(String testNumber, String vin, int iterations) {
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
String uuid = String.valueOf(UUID.randomUUID());
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(uuid);
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
String bucketName = loader.getS3Bucket();
String fileName = testNumber + "_" + vin + ".pdf";
String key = loader.getBranchName() + "/" + fileName;
AmazonS3 s3Client = new AmazonS3Client(temporaryCredentials);
System.out.println("Waiting on file " + key + " to be created... on bucket: " + bucketName);
System.out.println("time started checking " + DateTime.now().withZone(DateTimeZone.UTC));
for (int i = 0; i < iterations; i++) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (s3Client.doesObjectExist(bucketName, key)) {
System.out.println("time stopped checking " + DateTime.now().withZone(DateTimeZone.UTC));
System.out.println("file found in the s3 bucket... after " + i + " iterations");
return true;
}
}
System.out.println("time stopped checking " + DateTime.now().withZone(DateTimeZone.UTC));
System.out.println("file " + key + " was not created in 60 iterations or less...");
return false;
}
use of com.amazonaws.services.securitytoken.model.AssumeRoleRequest in project cvs-auto-svc by dvsa.
the class AwsUtil method getNextSystemNumberInSequence.
public static String getNextSystemNumberInSequence() {
Regions clientRegion = Regions.EU_WEST_1;
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withRegion(clientRegion).build();
String uuid = String.valueOf(UUID.randomUUID());
AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(System.getProperty("AWS_ROLE")).withDurationSeconds(3600).withRoleSessionName(uuid);
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(), assumeResult.getCredentials().getSessionToken());
AmazonDynamoDBClient client = new AmazonDynamoDBClient(temporaryCredentials);
client.setRegion(Region.getRegion(clientRegion));
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "cvs-" + loader.getBranchName() + "-test-number";
Table table = dynamoDB.getTable(tableName);
ItemCollection<ScanOutcome> items = // FilterExpression
table.scan(// FilterExpression
"attribute_exists(systemNumber)", // ProjectionExpression
"systemNumber", // ExpressionAttributeNames - not used in this example
null, // ExpressionAttributeValues - not used in this example
null);
System.out.println("Scan of " + tableName + " for items with systemNumber not null");
Iterator<Item> iterator = items.iterator();
String lastSystemNumberUsed = null;
while (iterator.hasNext()) {
lastSystemNumberUsed = GenericData.getValueFromJsonPath(iterator.next().toJSONPretty(), "$.systemNumber");
}
if (lastSystemNumberUsed != null) {
int nextSystemNumberInSequence = Integer.parseInt(lastSystemNumberUsed) + 1;
return Integer.toString(nextSystemNumberInSequence);
} else {
throw new AutomationException("No value found for last used systemNumber");
}
}
Aggregations