use of com.amazonaws.auth.AWSCredentialsProvider in project cas by apereo.
the class ChainingAWSCredentialsProvider method getCredentials.
@Override
public AWSCredentials getCredentials() {
LOGGER.debug("Attempting to locate AWS credentials from the chain...");
for (final AWSCredentialsProvider p : this.chain) {
AWSCredentials c;
try {
LOGGER.debug("Calling credential provider [{}] to fetch credentials...", p.getClass().getSimpleName());
c = p.getCredentials();
} catch (final Throwable e) {
LOGGER.trace(e.getMessage(), e);
c = null;
}
if (c != null) {
LOGGER.debug("Fetched credentials from [{}] provider successfully.", p.getClass().getSimpleName());
return c;
}
}
LOGGER.warn("No AWS credentials could be determined from the chain. Using anonymous credentials...");
return new AnonymousAWSCredentials();
}
use of com.amazonaws.auth.AWSCredentialsProvider in project druid by druid-io.
the class TestAWSCredentialsProvider method testWithFixedAWSKeys.
@Test
public void testWithFixedAWSKeys() {
AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
EasyMock.expect(config.getAccessKey()).andReturn("accessKeySample").atLeastOnce();
EasyMock.expect(config.getSecretKey()).andReturn("secretKeySample").atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
assertEquals(credentials.getAWSAccessKeyId(), "accessKeySample");
assertEquals(credentials.getAWSSecretKey(), "secretKeySample");
// try to create
s3Module.getRestS3Service(provider);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project elasticsearch by elastic.
the class AwsEc2ServiceImpl method buildCredentials.
protected static AWSCredentialsProvider buildCredentials(Logger logger, Settings settings) {
AWSCredentialsProvider credentials;
String key = CLOUD_EC2.KEY_SETTING.get(settings);
String secret = CLOUD_EC2.SECRET_SETTING.get(settings);
if (key.isEmpty() && secret.isEmpty()) {
logger.debug("Using either environment variables, system properties or instance profile credentials");
credentials = new DefaultAWSCredentialsProviderChain();
} else {
logger.debug("Using basic key/secret credentials");
credentials = new StaticCredentialsProvider(new BasicAWSCredentials(key, secret));
}
return credentials;
}
use of com.amazonaws.auth.AWSCredentialsProvider in project elasticsearch by elastic.
the class AwsS3ServiceImplTests method testAWSCredentialsWithSystemProviders.
public void testAWSCredentialsWithSystemProviders() {
AWSCredentialsProvider credentialsProvider = InternalAwsS3Service.buildCredentials(logger, deprecationLogger, Settings.EMPTY, Settings.EMPTY, "default");
assertThat(credentialsProvider, instanceOf(InternalAwsS3Service.PrivilegedInstanceProfileCredentialsProvider.class));
}
use of com.amazonaws.auth.AWSCredentialsProvider 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;
}
Aggregations