Search in sources :

Example 1 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider in project beam by apache.

the class AwsModuleTest method testSingletonAWSCredentialsProviderSerializationDeserialization.

@Test
public void testSingletonAWSCredentialsProviderSerializationDeserialization() throws Exception {
    AWSCredentialsProvider credentialsProvider;
    String serializedCredentialsProvider;
    AWSCredentialsProvider deserializedCredentialsProvider;
    credentialsProvider = new DefaultAWSCredentialsProviderChain();
    serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new EnvironmentVariableCredentialsProvider();
    serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new SystemPropertiesCredentialsProvider();
    serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new ProfileCredentialsProvider();
    serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new EC2ContainerCredentialsProviderWrapper();
    serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) EC2ContainerCredentialsProviderWrapper(com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper) Test(org.junit.Test)

Example 2 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider in project flink by apache.

the class AWSUtil method getCredentialsProvider.

/**
	 * Return a {@link AWSCredentialsProvider} instance corresponding to the configuration properties.
	 *
	 * @param configProps the configuration properties
	 * @return The corresponding AWS Credentials Provider instance
	 */
public static AWSCredentialsProvider getCredentialsProvider(final Properties configProps) {
    CredentialProvider credentialProviderType;
    if (!configProps.containsKey(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER)) {
        if (configProps.containsKey(AWSConfigConstants.AWS_ACCESS_KEY_ID) && configProps.containsKey(AWSConfigConstants.AWS_SECRET_ACCESS_KEY)) {
            // if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
            credentialProviderType = CredentialProvider.BASIC;
        } else {
            // if the credential provider type is not specified, it will default to AUTO
            credentialProviderType = CredentialProvider.AUTO;
        }
    } else {
        credentialProviderType = CredentialProvider.valueOf(configProps.getProperty(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER));
    }
    AWSCredentialsProvider credentialsProvider;
    switch(credentialProviderType) {
        case ENV_VAR:
            credentialsProvider = new EnvironmentVariableCredentialsProvider();
            break;
        case SYS_PROP:
            credentialsProvider = new SystemPropertiesCredentialsProvider();
            break;
        case PROFILE:
            String profileName = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_NAME, null);
            String profileConfigPath = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_PATH, null);
            credentialsProvider = (profileConfigPath == null) ? new ProfileCredentialsProvider(profileName) : new ProfileCredentialsProvider(profileConfigPath, profileName);
            break;
        case BASIC:
            credentialsProvider = new AWSCredentialsProvider() {

                @Override
                public AWSCredentials getCredentials() {
                    return new BasicAWSCredentials(configProps.getProperty(AWSConfigConstants.AWS_ACCESS_KEY_ID), configProps.getProperty(AWSConfigConstants.AWS_SECRET_ACCESS_KEY));
                }

                @Override
                public void refresh() {
                // do nothing
                }
            };
            break;
        default:
        case AUTO:
            credentialsProvider = new DefaultAWSCredentialsProviderChain();
    }
    return credentialsProvider;
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) CredentialProvider(org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.CredentialProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 3 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider 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 4 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider 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 5 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider in project carina by qaprosoft.

the class AmazonS3Manager method getInstance.

public static AmazonS3Manager getInstance() {
    if (instance == null) {
        synchronized (AmazonS3Manager.class) {
            if (instance == null) {
                instance = new AmazonS3Manager();
                String accessKey = Configuration.get(Parameter.ACCESS_KEY_ID);
                String secretKey = Configuration.get(Parameter.SECRET_KEY);
                System.setProperty("aws.accessKeyId", accessKey);
                System.setProperty("aws.secretKey", secretKey);
                s3client = new AmazonS3Client(new SystemPropertiesCredentialsProvider());
            }
        }
    }
    return instance;
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider)

Aggregations

SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)9 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)8 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)5 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)5 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)4 Test (org.junit.Test)4 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 EC2ContainerCredentialsProviderWrapper (com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)1 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)1 PropertiesFileCredentialsProvider (com.amazonaws.auth.PropertiesFileCredentialsProvider)1 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)1 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1