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