Search in sources :

Example 21 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project cas by apereo.

the class ChainingAWSCredentialsProvider method getInstance.

/**
 * Gets instance.
 *
 * @param credentialAccessKey      the credential access key
 * @param credentialSecretKey      the credential secret key
 * @param credentialPropertiesFile the credential properties file
 * @param profilePath              the profile path
 * @param profileName              the profile name
 * @return the instance
 */
public static AWSCredentialsProvider getInstance(final String credentialAccessKey, final String credentialSecretKey, final Resource credentialPropertiesFile, final String profilePath, final String profileName) {
    LOGGER.debug("Attempting to locate AWS credentials...");
    final List<AWSCredentialsProvider> chain = new ArrayList<>();
    chain.add(new InstanceProfileCredentialsProvider(false));
    if (credentialPropertiesFile != null) {
        try {
            final File f = credentialPropertiesFile.getFile();
            chain.add(new PropertiesFileCredentialsProvider(f.getCanonicalPath()));
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    if (StringUtils.isNotBlank(profilePath) && StringUtils.isNotBlank(profileName)) {
        chain.add(new ProfileCredentialsProvider(profilePath, profileName));
    }
    chain.add(new SystemPropertiesCredentialsProvider());
    chain.add(new EnvironmentVariableCredentialsProvider());
    chain.add(new ClasspathPropertiesFileCredentialsProvider("awscredentials.properties"));
    if (StringUtils.isNotBlank(credentialAccessKey) && StringUtils.isNotBlank(credentialSecretKey)) {
        final BasicAWSCredentials credentials = new BasicAWSCredentials(credentialAccessKey, credentialSecretKey);
        chain.add(new AWSStaticCredentialsProvider(credentials));
    }
    LOGGER.debug("AWS chained credential providers are configured as [{}]", chain);
    return new ChainingAWSCredentialsProvider(chain);
}
Also used : InstanceProfileCredentialsProvider(com.amazonaws.auth.InstanceProfileCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) ArrayList(java.util.ArrayList) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClasspathPropertiesFileCredentialsProvider(com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider) PropertiesFileCredentialsProvider(com.amazonaws.auth.PropertiesFileCredentialsProvider) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) InstanceProfileCredentialsProvider(com.amazonaws.auth.InstanceProfileCredentialsProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) File(java.io.File) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClasspathPropertiesFileCredentialsProvider(com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)

Example 22 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project cas by apereo.

the class AmazonDynamoDbClientFactory method createAmazonDynamoDb.

/**
 * Create amazon dynamo db instance.
 *
 * @param dynamoDbProperties the dynamo db properties
 * @return the amazon dynamo db
 */
@SneakyThrows
public AmazonDynamoDB createAmazonDynamoDb(final AbstractDynamoDbProperties dynamoDbProperties) {
    if (dynamoDbProperties.isLocalInstance()) {
        LOGGER.debug("Creating DynamoDb standard client with endpoint [{}] and region [{}]", dynamoDbProperties.getEndpoint(), dynamoDbProperties.getRegion());
        final AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(dynamoDbProperties.getEndpoint(), dynamoDbProperties.getRegion());
        return AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(endpoint).build();
    }
    final AWSCredentialsProvider provider = ChainingAWSCredentialsProvider.getInstance(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey(), dynamoDbProperties.getCredentialsPropertiesFile());
    LOGGER.debug("Creating DynamoDb client configuration...");
    final ClientConfiguration cfg = new ClientConfiguration();
    cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
    cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
    cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
    cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
    cfg.setUseGzip(dynamoDbProperties.isUseGzip());
    cfg.setUseReaper(dynamoDbProperties.isUseReaper());
    cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
    cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
    cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
    cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
    cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
    if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
        LOGGER.debug("Creating DynamoDb client local address [{}]", dynamoDbProperties.getLocalAddress());
        cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
    }
    LOGGER.debug("Creating DynamoDb client instance...");
    final AmazonDynamoDBClient client = new AmazonDynamoDBClient(provider, cfg);
    if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
        LOGGER.debug("Setting DynamoDb client endpoint [{}]", dynamoDbProperties.getEndpoint());
        client.setEndpoint(dynamoDbProperties.getEndpoint());
    }
    if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
        LOGGER.debug("Setting DynamoDb client region [{}]", dynamoDbProperties.getRegion());
        client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
    }
    if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
        LOGGER.debug("Setting DynamoDb client region override [{}]", dynamoDbProperties.getRegionOverride());
        client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
    }
    if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
        client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
    }
    if (dynamoDbProperties.getTimeOffset() != 0) {
        client.setTimeOffset(dynamoDbProperties.getTimeOffset());
    }
    return client;
}
Also used : AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) ChainingAWSCredentialsProvider(org.apereo.cas.aws.ChainingAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClientConfiguration(com.amazonaws.ClientConfiguration) SneakyThrows(lombok.SneakyThrows)

Example 23 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project hippo by NHS-digital-website.

the class S3ConnectorServiceRegistrationModule method getAmazonS3.

private AmazonS3 getAmazonS3() {
    AWSCredentialsProvider provider = new SystemPropertiesCredentialsProvider();
    AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard().withCredentials(provider).withRegion(Regions.fromName(s3Region));
    if (!s3Endpoint.isEmpty()) {
        s3Builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3Endpoint, s3Region));
    }
    return s3Builder.build();
}
Also used : SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 24 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project apex-malhar by apache.

the class KinesisTestProducer method createClient.

private void createClient() {
    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
    client = new AmazonKinesisClient(credentials);
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 25 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project apex-malhar by apache.

the class KinesisTestConsumer method createClient.

private void createClient() {
    AWSCredentialsProvider credentials = new DefaultAWSCredentialsProviderChain();
    client = new AmazonKinesisClient(credentials);
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)25 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)7 Test (org.junit.Test)7 AWSCredentials (com.amazonaws.auth.AWSCredentials)6 Configuration (org.apache.hadoop.conf.Configuration)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 URI (java.net.URI)4 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 ClientConfiguration (com.amazonaws.ClientConfiguration)2 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)2 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)2 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)2 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)2 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)2 AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)2 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)2 AWSCredentialsConfig (io.druid.common.aws.AWSCredentialsConfig)2 File (java.io.File)2 AmazonClientException (com.amazonaws.AmazonClientException)1