List of usage examples for com.amazonaws.services.securitytoken.model AssumeRoleRequest setExternalId
public void setExternalId(String externalId)
A unique identifier that might be required when you assume a role in another account.
From source file:com.netflix.ice.common.AwsUtils.java
License:Apache License
/** * Get assumes IAM credentials./*from w ww.j av a 2s . c o m*/ * @param accountId * @param assumeRole * @return assumes IAM credentials */ public static Credentials getAssumedCredentials(String accountId, String assumeRole, String externalId) { AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest() .withRoleArn("arn:aws:iam::" + accountId + ":role/" + assumeRole) .withRoleSessionName(assumeRole.substring(0, Math.min(assumeRole.length(), 32))); if (!StringUtils.isEmpty(externalId)) assumeRoleRequest.setExternalId(externalId); AssumeRoleResult roleResult = securityClient.assumeRole(assumeRoleRequest); return roleResult.getCredentials(); }
From source file:jetbrains.buildServer.util.amazon.AWSClients.java
License:Apache License
@NotNull public AWSSessionCredentials createSessionCredentials(@NotNull String iamRoleARN, @Nullable String externalID, @NotNull String sessionName, int sessionDuration) throws AWSException { final AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(iamRoleARN) .withRoleSessionName(sessionName).withDurationSeconds(sessionDuration); if (StringUtil.isNotEmpty(externalID)) assumeRoleRequest.setExternalId(externalID); try {// w w w . jav a2 s . co m final Credentials credentials = createSecurityTokenServiceClient().assumeRole(assumeRoleRequest) .getCredentials(); return new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()); } catch (Exception e) { throw new AWSException(e); } }