Search in sources :

Example 1 with ClasspathPropertiesFileCredentialsProvider

use of com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider 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)

Aggregations

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