Search in sources :

Example 11 with AWSCredentialsProvider

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();
}
Also used : AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 12 with AWSCredentialsProvider

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);
}
Also used : AWSCredentialsConfig(io.druid.common.aws.AWSCredentialsConfig) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 13 with AWSCredentialsProvider

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;
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 14 with AWSCredentialsProvider

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));
}
Also used : AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 15 with AWSCredentialsProvider

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;
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) CredentialProvider(org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.CredentialProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)25 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)7 Test (org.junit.Test)7 AWSCredentials (com.amazonaws.auth.AWSCredentials)6 Configuration (org.apache.hadoop.conf.Configuration)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 URI (java.net.URI)4 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 ClientConfiguration (com.amazonaws.ClientConfiguration)2 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)2 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)2 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)2 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)2 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)2 AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)2 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)2 AWSCredentialsConfig (io.druid.common.aws.AWSCredentialsConfig)2 File (java.io.File)2 AmazonClientException (com.amazonaws.AmazonClientException)1