Search in sources :

Example 1 with PropertiesFileCredentialsProvider

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

the class AwsSerializableUtilsTest method testPropertiesFileCredentialsProviderSerialization.

@Test
public void testPropertiesFileCredentialsProviderSerialization() {
    AWSCredentialsProvider credentialsProvider = new PropertiesFileCredentialsProvider("AwsCredentials.properties");
    String expectedSerializedProvider = "{\"@type\":\"PropertiesFileCredentialsProvider\",\"credentialsFilePath\":\"AwsCredentials.properties\"}";
    String serializedProvider = serialize(credentialsProvider);
    assertEquals(expectedSerializedProvider, serializedProvider);
    assertEquals(expectedSerializedProvider, serialize(deserialize(serializedProvider)));
}
Also used : ClasspathPropertiesFileCredentialsProvider(com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider) PropertiesFileCredentialsProvider(com.amazonaws.auth.PropertiesFileCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 2 with PropertiesFileCredentialsProvider

use of com.amazonaws.auth.PropertiesFileCredentialsProvider 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 3 with PropertiesFileCredentialsProvider

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

the class AwsModuleTest method testPropertiesFileCredentialsProviderSerializationDeserialization.

@Test
public void testPropertiesFileCredentialsProviderSerializationDeserialization() throws Exception {
    String credentialsFilePath = "/path/to/file";
    AWSCredentialsProvider credentialsProvider = new PropertiesFileCredentialsProvider(credentialsFilePath);
    String serializedCredentialsProvider = serialize(credentialsProvider);
    AWSCredentialsProvider deserializedCredentialsProvider = deserializeCredentialsProvider(serializedCredentialsProvider);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    assertEquals(credentialsFilePath, readField(deserializedCredentialsProvider, "credentialsFilePath", true));
}
Also used : ClasspathPropertiesFileCredentialsProvider(com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider) PropertiesFileCredentialsProvider(com.amazonaws.auth.PropertiesFileCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 4 with PropertiesFileCredentialsProvider

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

the class AwsModuleTest method testPropertiesFileCredentialsProviderSerializationDeserialization.

@Test
public void testPropertiesFileCredentialsProviderSerializationDeserialization() throws Exception {
    String credentialsFilePath = "/path/to/file";
    PropertiesFileCredentialsProvider credentialsProvider = new PropertiesFileCredentialsProvider(credentialsFilePath);
    String serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
    AWSCredentialsProvider deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    assertEquals(credentialsFilePath, readField(deserializedCredentialsProvider, "credentialsFilePath", true));
}
Also used : ClasspathPropertiesFileCredentialsProvider(com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider) PropertiesFileCredentialsProvider(com.amazonaws.auth.PropertiesFileCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)4 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)4 PropertiesFileCredentialsProvider (com.amazonaws.auth.PropertiesFileCredentialsProvider)4 Test (org.junit.Test)3 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)1 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)1 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1