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);
}
Aggregations