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:com.formkiq.core.service.AssetServiceS3Default.java

License:Apache License

/**
 * @return {@link AmazonS3}//w  w  w .ja  va 2s  . c  om
 */
private AmazonS3 getS3Connection() {

    if (this.s3client == null) {
        AWSCredentials credentials = new BasicAWSCredentials(this.s3AccessKey, this.s3AccessSecret);
        this.s3client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_WEST_2) // TODO create aws.properties
                .build();
    }

    return this.s3client;
}

From source file:com.github.vatbub.awsvpnlauncher.Main.java

License:Apache License

private static void initAWSConnection() {
    AWSCredentials credentials = new BasicAWSCredentials(prefs.getPreference(Property.awsKey),
            prefs.getPreference(Property.awsSecret));
    awsRegion = Regions.valueOf(prefs.getPreference(Property.awsRegion));
    client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
            .withRegion(awsRegion).build();
}

From source file:com.kurtraschke.nyctrtproxy.services.CloudwatchProxyDataListener.java

License:Apache License

@PostConstruct
public void init() {
    if (_secretKey == null || _accessKey == null || _namespace == null) {
        _log.info("No AWS credentials supplied, disabling cloudwatch");
        _disabled = true;//from ww w .j a  va  2 s  .co m
        return;
    }
    BasicAWSCredentials cred = new BasicAWSCredentials(_accessKey, _secretKey);
    _client = AmazonCloudWatchAsyncClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(cred)).build();
    _handler = new AsyncHandler<PutMetricDataRequest, PutMetricDataResult>() {
        @Override
        public void onError(Exception e) {
            _log.error("Error sending to cloudwatch: " + e);
        }

        @Override
        public void onSuccess(PutMetricDataRequest request, PutMetricDataResult putMetricDataResult) {
            // do nothing
        }
    };
}

From source file:com.netflix.genie.web.util.S3ClientFactory.java

License:Apache License

/**
 * Get an S3 client given the configuration of the system.
 *
 * @return an S3 client/*from w w w .  j  a  va 2  s  . c o  m*/
 */
public AmazonS3 getS3Client() {
    if (this.assumeRole) {
        // TODO: It's possible this could be optimized to reuse a client that a role has already been assumed for
        //       it would take more logic in this class and likely isn't worth it right now before we decide how
        //       4.x may work best. As it is now create a new client every time one is requested to assume a role

        // See: https://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingTempSessionTokenJava.html
        final AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
                .withCredentials(this.awsCredentialsProvider)
                .withClientConfiguration(this.awsClientConfiguration).withRegion(this.awsRegion).build();

        final AssumeRoleRequest roleRequest = new AssumeRoleRequest().withRoleArn(this.roleArn)
                .withRoleSessionName("Genie-" + UUID.randomUUID().toString());

        final AssumeRoleResult roleResult = stsClient.assumeRole(roleRequest);
        final Credentials sessionCredentials = roleResult.getCredentials();

        final BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(
                sessionCredentials.getAccessKeyId(), sessionCredentials.getSecretAccessKey(),
                sessionCredentials.getSessionToken());

        return AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(basicSessionCredentials))
                .withClientConfiguration(this.awsClientConfiguration).withRegion(this.awsRegion).build();
    } else {
        return this.defaultS3Client;
    }
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.s3.S3ArtifactCredentials.java

License:Apache License

private AmazonS3 getS3Client() {
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();

    if (!StringUtils.isEmpty(apiEndpoint)) {
        AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(
                apiEndpoint, apiRegion);
        builder.setEndpointConfiguration(endpoint);
        builder.setPathStyleAccessEnabled(true);
    } else if (!StringUtils.isEmpty(region)) {
        builder.setRegion(region);//www  .j  a v a2  s .c  o m
    }

    if (!StringUtils.isEmpty(awsAccessKeyId) && !StringUtils.isEmpty(awsSecretAccessKey)) {
        BasicAWSCredentials awsStaticCreds = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey);
        builder.withCredentials(new AWSStaticCredentialsProvider(awsStaticCreds));
    }

    return builder.build();
}

From source file:com.netflix.spinnaker.halyard.config.validate.v1.providers.aws.AwsAccountValidator.java

License:Apache License

public static AWSCredentialsProvider getAwsCredentialsProvider(String accessKeyId, String secretKey) {
    if (accessKeyId != null && secretKey != null) {
        return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretKey));
    } else {//from  w  w w .  java 2s .  co m
        return DefaultAWSCredentialsProviderChain.getInstance();
    }
}

From source file:com.streamsets.datacollector.credential.aws.secrets.manager.AWSSecretsManagerCredentialStore.java

License:Apache License

protected SecretCache createSecretCache(String awsAccessKey, String awsSecretKey, String region, int cacheSize,
        long cacheTTL) {
    AWSCredentialsProvider credentials = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(awsAccessKey, awsSecretKey));
    AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard().withRegion(region)
            .withCredentials(credentials);

    SecretCacheConfiguration cacheConf = new SecretCacheConfiguration().withMaxCacheSize(cacheSize)
            .withCacheItemTTL(cacheTTL).withClient(clientBuilder.build());

    return new SecretCache(cacheConf);
}

From source file:com.streamsets.datacollector.lib.emr.S3Manager.java

License:Apache License

private AmazonS3 getS3Client() {
    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(pipelineEmrConfigs.getAccessKey(), pipelineEmrConfigs.getSecretKey()));

    AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(pipelineEmrConfigs.getUserRegion())
            .withCredentials(credentialsProvider).build();
    return s3Client;
}

From source file:com.streamsets.pipeline.lib.aws.AwsUtil.java

License:Apache License

public static AWSCredentialsProvider getCredentialsProvider(CredentialValue accessKeyId,
        CredentialValue secretKey) throws StageException {
    AWSCredentialsProvider credentialsProvider;
    if (accessKeyId != null && secretKey != null && !accessKeyId.get().isEmpty()
            && !secretKey.get().isEmpty()) {
        credentialsProvider = new AWSStaticCredentialsProvider(
                new BasicAWSCredentials(accessKeyId.get(), secretKey.get()));
    } else {/*from  w ww.  j  a va  2s  .c o  m*/
        credentialsProvider = new DefaultAWSCredentialsProviderChain();
    }
    return credentialsProvider;
}

From source file:com.streamsets.pipeline.lib.aws.s3.S3Accessor.java

License:Apache License

AWSCredentialsProvider createCredentialsProvider() throws StageException {
    return new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentialConfigs.getAccessKey().get(),
            credentialConfigs.getSecretKey().get()));
}