Example usage for com.amazonaws.services.securitytoken.model AssumeRoleRequest setRoleArn

List of usage examples for com.amazonaws.services.securitytoken.model AssumeRoleRequest setRoleArn

Introduction

In this page you can find the example usage for com.amazonaws.services.securitytoken.model AssumeRoleRequest setRoleArn.

Prototype


public void setRoleArn(String roleArn) 

Source Link

Document

The Amazon Resource Name (ARN) of the role to assume.

Usage

From source file:com.dtolabs.rundeck.plugin.resources.ec2.EC2ResourceModelSource.java

License:Apache License

private void initialize() {
    final ArrayList<String> params = new ArrayList<String>();
    if (null != filterParams) {
        Collections.addAll(params, filterParams.split(";"));
    }/*from  w ww . j a  va  2s  . co  m*/
    loadMapping();
    if (this.credentials == null && assumeRoleArn != null) {
        AWSSecurityTokenServiceClient sts_client = new AWSSecurityTokenServiceClient();
        //        sts_client.setEndpoint("sts-endpoint.amazonaws.com");
        AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
        assumeRoleRequest.setRoleArn(assumeRoleArn);
        assumeRoleRequest.setRoleSessionName("RundeckEC2ResourceModelSourceSession");
        AssumeRoleResult assumeRoleResult = sts_client.assumeRole(assumeRoleRequest);
        Credentials assumeCredentials = assumeRoleResult.getCredentials();
        credentials = new BasicSessionCredentials(assumeCredentials.getAccessKeyId(),
                assumeCredentials.getSecretAccessKey(), assumeCredentials.getSessionToken());
    }

    mapper = new InstanceToNodeMapper(this.credentials, mapping, clientConfiguration);
    mapper.setFilterParams(params);
    mapper.setEndpoint(endpoint);
    mapper.setRunningStateOnly(runningOnly);
}

From source file:com.yahoo.athenz.zts.store.CloudStore.java

License:Apache License

AssumeRoleRequest getAssumeRoleRequest(String account, String roleName, String principal) {

    // assume the target role to get the credentials for the client
    // aws format is arn:aws:iam::<account-id>:role/<role-name>

    String arn = "arn:aws:iam::" + account + ":role/" + roleName;

    AssumeRoleRequest req = new AssumeRoleRequest();
    req.setRoleArn(arn);
    req.setRoleSessionName(principal);/*w w w  . ja  va2  s  .c  om*/

    return req;
}

From source file:com.yahoo.athenz.zts.ZTSClient.java

License:Apache License

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);//  ww  w .  jav a2s  .  c o  m

    return req;
}

From source file:org.finra.dm.dao.impl.StsDaoImpl.java

License:Apache License

/**
 * Returns a set of temporary security credentials (consisting of an access key ID, a secret access key, and a security token) that can be used to access
 * the specified AWS resource.//from  w  w w.j a  va 2  s  .  c  om
 *
 * @param sessionName the session name that will be associated with the temporary credentials. The session name must be the same for an initial set of
 * credentials and an extended set of credentials if credentials are to be refreshed. The session name also is used to identify the user in AWS logs so it
 * should be something unique and useful to identify the caller/use.
 * @param awsRoleArn the AWS ARN for the role required to provide access to the specified AWS resource
 * @param awsRoleDurationSeconds the duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) to 3600 seconds (1 hour).
 * @param policy the temporary policy to apply to this request
 *
 * @return the assumed session credentials
 */
@Override
public Credentials getTemporarySecurityCredentials(AwsParamsDto awsParamsDto, String sessionName,
        String awsRoleArn, int awsRoleDurationSeconds, Policy policy) {
    // Construct a new AWS security token service client using the specified client configuration to access Amazon S3.
    // A credentials provider chain will be used that searches for credentials in this order:
    // - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
    // - Java System Properties - aws.accessKeyId and aws.secretKey
    // - Instance Profile Credentials - delivered through the Amazon EC2 metadata service

    ClientConfiguration clientConfiguration = new ClientConfiguration();

    // Only set the proxy hostname and/or port if they're configured.
    if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) {
        clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost());
    }
    if (awsParamsDto.getHttpProxyPort() != null) {
        clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort());
    }

    AWSSecurityTokenServiceClient awsSecurityTokenServiceClient = new AWSSecurityTokenServiceClient(
            clientConfiguration);

    // Create the request.
    AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
    assumeRoleRequest.setRoleSessionName(sessionName);
    assumeRoleRequest.setRoleArn(awsRoleArn);
    assumeRoleRequest.setDurationSeconds(awsRoleDurationSeconds);
    assumeRoleRequest.setPolicy(policy.toJson());

    // Get the temporary security credentials.
    AssumeRoleResult assumeRoleResult = stsOperations.assumeRole(awsSecurityTokenServiceClient,
            assumeRoleRequest);
    return assumeRoleResult.getCredentials();
}

From source file:org.finra.herd.dao.impl.StsDaoImpl.java

License:Apache License

/**
 * Returns a set of temporary security credentials (consisting of an access key ID, a secret access key, and a security token) that can be used to access
 * the specified AWS resource./*w w w .j  a v a  2s .  c o  m*/
 *
 * @param sessionName the session name that will be associated with the temporary credentials. The session name must be the same for an initial set of
 * credentials and an extended set of credentials if credentials are to be refreshed. The session name also is used to identify the user in AWS logs so it
 * should be something unique and useful to identify the caller/use.
 * @param awsRoleArn the AWS ARN for the role required to provide access to the specified AWS resource
 * @param awsRoleDurationSeconds the duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) to 3600 seconds (1 hour).
 * @param policy the temporary policy to apply to this request
 *
 * @return the assumed session credentials
 */
@Override
public Credentials getTemporarySecurityCredentials(AwsParamsDto awsParamsDto, String sessionName,
        String awsRoleArn, int awsRoleDurationSeconds, Policy policy) {
    // Construct a new AWS security token service client using the specified client configuration to access Amazon S3.
    // A credentials provider chain will be used that searches for credentials in this order:
    // - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
    // - Java System Properties - aws.accessKeyId and aws.secretKey
    // - Instance Profile Credentials - delivered through the Amazon EC2 metadata service

    ClientConfiguration clientConfiguration = new ClientConfiguration()
            .withRetryPolicy(retryPolicyFactory.getRetryPolicy());

    // Only set the proxy hostname and/or port if they're configured.
    if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) {
        clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost());
    }
    if (awsParamsDto.getHttpProxyPort() != null) {
        clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort());
    }

    AWSSecurityTokenServiceClient awsSecurityTokenServiceClient = new AWSSecurityTokenServiceClient(
            clientConfiguration);

    // Create the request.
    AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
    assumeRoleRequest.setRoleSessionName(sessionName);
    assumeRoleRequest.setRoleArn(awsRoleArn);
    assumeRoleRequest.setDurationSeconds(awsRoleDurationSeconds);
    if (policy != null) {
        assumeRoleRequest.setPolicy(policy.toJson());
    }

    // Get the temporary security credentials.
    AssumeRoleResult assumeRoleResult = stsOperations.assumeRole(awsSecurityTokenServiceClient,
            assumeRoleRequest);
    return assumeRoleResult.getCredentials();
}