Example usage for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider

List of usage examples for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSStaticCredentialsProvider AWSStaticCredentialsProvider.

Prototype

public AWSStaticCredentialsProvider(AWSCredentials credentials) 

Source Link

Usage

From source file:org.duracloud.notification.AmazonNotificationFactory.java

License:Apache License

@Override
public void initialize(String accessKey, String secretKey) {
    if (StringUtils.isNotBlank(accessKey)) {
        log.debug("initialize email service with provided credentials");
        emailService = AmazonSimpleEmailServiceAsyncClientBuilder.standard()
                .withCredentials(//  w  ww  .java  2s .  co m
                        new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
                .build();
    } else {
        log.debug("initialize email service using the default AWS Default Credentials Chain provider");
        emailService = AmazonSimpleEmailServiceAsyncClientBuilder.defaultClient();
    }
}

From source file:org.duracloud.s3storage.S3ProviderUtil.java

License:Apache License

private static AmazonS3 newS3Client(String accessKey, String secretKey, Region region) {
    BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    try {//from   w  w w .jav a  2 s.c o  m
        String awsRegion = null;
        if (region != null) {
            awsRegion = region.getName();
        } else {
            awsRegion = System.getProperty(AWS_REGION.name());
        }
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).withRegion(awsRegion)
                .build();
        return s3Client;
    } catch (AmazonServiceException e) {
        String err = "Could not create connection to Amazon S3 due " + "to error: " + e.getMessage();
        throw new StorageException(err, e, RETRY);
    }
}

From source file:org.finra.herd.dao.AwsClientFactory.java

License:Apache License

/**
 * Creates a client for accessing Amazon EC2 service.
 *
 * @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information
 *
 * @return the Amazon EC2 client/*ww w .j  a v  a  2 s  .  co  m*/
 */
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public AmazonEC2 getEc2Client(AwsParamsDto awsParamsDto) {
    // Get client configuration.
    ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto);

    // If specified, use the AWS credentials passed in.
    if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId())) {
        return AmazonEC2ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(
                        new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(),
                                awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken())))
                .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName())
                .build();
    }
    // Otherwise, use the default AWS credentials provider chain.
    else {
        return AmazonEC2ClientBuilder.standard().withClientConfiguration(clientConfiguration)
                .withRegion(awsParamsDto.getAwsRegionName()).build();
    }
}

From source file:org.finra.herd.dao.AwsClientFactory.java

License:Apache License

/**
 * Creates a client for accessing Amazon EMR service.
 *
 * @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information
 *
 * @return the Amazon EMR client// ww w  .j  ava  2s  . c o m
 */
@Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
public AmazonElasticMapReduce getEmrClient(AwsParamsDto awsParamsDto) {
    // Get client configuration.
    ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto);

    // If specified, use the AWS credentials passed in.
    if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId())) {
        return AmazonElasticMapReduceClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(
                        new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(),
                                awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken())))
                .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName())
                .build();
    }
    // Otherwise, use the default AWS credentials provider chain.
    else {
        return AmazonElasticMapReduceClientBuilder.standard().withClientConfiguration(clientConfiguration)
                .withRegion(awsParamsDto.getAwsRegionName()).build();
    }
}

From source file:org.jooby.internal.aws.CredentialsFactory.java

License:Apache License

private static void applicationCredentials(Config conf, String serviceName,
        Consumer<AWSCredentialsProvider> consumer) {
    String accessKey = find(conf, "aws." + serviceName + "." + ACCESS_KEY, "aws." + ACCESS_KEY);
    if (accessKey != null) {
        String secretKey = find(conf, "aws." + serviceName + "." + SECRET_KEY, "aws." + SECRET_KEY);
        String sessionToken = find(conf, "aws." + serviceName + "." + SESSION_TOKEN, "aws." + SESSION_TOKEN);
        AWSCredentials credentials = sessionToken == null ? new BasicAWSCredentials(accessKey, secretKey)
                : new BasicSessionCredentials(accessKey, secretKey, sessionToken);
        consumer.accept(new AWSStaticCredentialsProvider(credentials));
    }/*from ww  w .j ava  2  s.  c  om*/
}

From source file:org.openhab.voice.pollytts.internal.cloudapi.PollyTTSCloudImpl.java

License:Open Source License

public PollyTTSCloudImpl(PollyTTSConfig config) {
    this.config = config;

    AWSCredentials credentials = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey());
    client = AmazonPollyClientBuilder.standard().withRegion(config.getServiceRegion())
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
    voices = client.describeVoices(new DescribeVoicesRequest()).getVoices();

    // create voice to ID translation for service invocation
    labelToID = voices.stream().collect(toMap(Voice::getName, Voice::getId));
}

From source file:org.ow2.proactive.scheduler.examples.S3ConnectorUtils.java

License:Open Source License

/**
 * Get or initialize the S3 client./*  w w  w  .  j av  a  2s  .  c o  m*/
 * Note: this method must be synchronized because we're accessing the
 * field and we're calling this method from a worker thread.
 *
 * @return the S3 client
 */
protected static synchronized AmazonS3 getS3Client(String accessKey, String secretKey, String... args) {

    BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(credentials));

    if (args.length == 1) {
        builder = builder.withRegion(args[0]);

    } else {
        String endpoint = args[0] + "://" + args[1];
        String clientRegion = null;
        if (!ServiceUtils.isS3USStandardEndpoint(endpoint) && (clientRegion = AwsHostNameUtils
                .parseRegion(args[1], AmazonS3Client.S3_SERVICE_NAME)) == null) {
            throw new IllegalArgumentException("Invalid region in " + args[1]);
        }
        builder = builder
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, clientRegion));
    }
    builder = builder.withPathStyleAccessEnabled(true);
    return builder.build();
}

From source file:org.pentaho.amazon.client.impl.AimClientFactory.java

License:Apache License

@Override
public AimClient createClient(String accessKey, String secretKey, String region) {
    AmazonClientCredentials clientCredentials = new AmazonClientCredentials(accessKey, secretKey, region);

    AmazonIdentityManagement awsAimClient = AmazonIdentityManagementClientBuilder.standard()
            .withRegion(clientCredentials.getRegion())
            .withCredentials(new AWSStaticCredentialsProvider(clientCredentials.getAWSCredentials())).build();

    AimClient aimClient = new AimClientImpl(awsAimClient);
    return aimClient;
}

From source file:org.pentaho.amazon.client.impl.EmrClientFactory.java

License:Apache License

@Override
public EmrClient createClient(String accessKey, String secretKey, String region) {
    AmazonClientCredentials clientCredentials = new AmazonClientCredentials(accessKey, secretKey, region);

    AmazonElasticMapReduce awsEmrClient = AmazonElasticMapReduceClientBuilder.standard()
            .withRegion(clientCredentials.getRegion())
            .withCredentials(new AWSStaticCredentialsProvider(clientCredentials.getAWSCredentials())).build();

    EmrClient emrClient = new EmrClientImpl(awsEmrClient);

    return emrClient;
}

From source file:org.pentaho.amazon.client.impl.PricingClientFactory.java

License:Apache License

@Override
public PricingClient createClient(String accessKey, String secretKey, String region) {
    AmazonClientCredentials clientCredentials = new AmazonClientCredentials(accessKey, secretKey, region);

    AWSPricing awsPricingClient = AWSPricingAsyncClientBuilder.standard()
            .withRegion(Region.US_Standard.toAWSRegion().getName())
            .withCredentials(new AWSStaticCredentialsProvider(clientCredentials.getAWSCredentials())).build();

    PricingClient pricingClient = new PricingClientImpl(awsPricingClient, region);

    return pricingClient;
}