Search in sources :

Example 71 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project hadoop by apache.

the class TestS3AAWSCredentialsProvider method assertCredentialProviders.

/**
   * Asserts expected provider classes in list.
   * @param expectedClasses expected provider classes
   * @param list providers to check
   */
private static void assertCredentialProviders(List<Class<? extends AWSCredentialsProvider>> expectedClasses, AWSCredentialProviderList list) {
    assertNotNull(list);
    List<AWSCredentialsProvider> providers = list.getProviders();
    assertEquals(expectedClasses.size(), providers.size());
    for (int i = 0; i < expectedClasses.size(); ++i) {
        Class<? extends AWSCredentialsProvider> expectedClass = expectedClasses.get(i);
        AWSCredentialsProvider provider = providers.get(i);
        assertNotNull(String.format("At position %d, expected class is %s, but found null.", i, expectedClass), provider);
        assertTrue(String.format("At position %d, expected class is %s, but found %s.", i, expectedClass, provider.getClass()), expectedClass.isAssignableFrom(provider.getClass()));
    }
}
Also used : AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 72 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project hadoop by apache.

the class TestS3AAWSCredentialsProvider method testInstantiationChain.

@Test
public void testInstantiationChain() throws Throwable {
    Configuration conf = new Configuration();
    conf.set(AWS_CREDENTIALS_PROVIDER, TemporaryAWSCredentialsProvider.NAME + ", \t" + SimpleAWSCredentialsProvider.NAME + " ,\n " + AnonymousAWSCredentialsProvider.NAME);
    Path testFile = new Path(conf.getTrimmed(KEY_CSVTEST_FILE, DEFAULT_CSVTEST_FILE));
    URI uri = testFile.toUri();
    AWSCredentialProviderList list = S3AUtils.createAWSCredentialProviderSet(uri, conf, uri);
    List<Class<? extends AWSCredentialsProvider>> expectedClasses = Arrays.asList(TemporaryAWSCredentialsProvider.class, SimpleAWSCredentialsProvider.class, AnonymousAWSCredentialsProvider.class);
    assertCredentialProviders(expectedClasses, list);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 73 with AWSCredentialsProvider

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

Example 74 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project nifi by apache.

the class CredentialsProviderFactory method getCredentialsProvider.

/**
 * Produces the AWSCredentialsProvider according to the given property set and the strategies configured in
 * the factory.
 * @return AWSCredentialsProvider implementation
 */
public AWSCredentialsProvider getCredentialsProvider(final Map<PropertyDescriptor, String> properties) {
    final CredentialsStrategy primaryStrategy = selectPrimaryStrategy(properties);
    AWSCredentialsProvider primaryCredentialsProvider = primaryStrategy.getCredentialsProvider(properties);
    AWSCredentialsProvider derivedCredentialsProvider = null;
    for (CredentialsStrategy strategy : strategies) {
        if (strategy.canCreateDerivedCredential(properties)) {
            derivedCredentialsProvider = strategy.getDerivedCredentialsProvider(properties, primaryCredentialsProvider);
            break;
        }
    }
    if (derivedCredentialsProvider != null) {
        return derivedCredentialsProvider;
    } else {
        return primaryCredentialsProvider;
    }
}
Also used : ExplicitDefaultCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.ExplicitDefaultCredentialsStrategy) AccessKeyPairCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AccessKeyPairCredentialsStrategy) AnonymousCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AnonymousCredentialsStrategy) AssumeRoleCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.AssumeRoleCredentialsStrategy) ImplicitDefaultCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.ImplicitDefaultCredentialsStrategy) NamedProfileCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.NamedProfileCredentialsStrategy) FileCredentialsStrategy(org.apache.nifi.processors.aws.credentials.provider.factory.strategies.FileCredentialsStrategy) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 75 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project nifi by apache.

the class TestAWSCredentials method setUp.

@Before
public void setUp() {
    mockAwsProcessor = new AbstractAWSCredentialsProviderProcessor<AmazonS3Client>() {

        protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
            return Arrays.asList(AbstractAWSCredentialsProviderProcessor.AWS_CREDENTIALS_PROVIDER_SERVICE, AbstractAWSProcessor.CREDENTIALS_FILE, AbstractAWSProcessor.ACCESS_KEY, AbstractAWSProcessor.SECRET_KEY, AbstractAWSProcessor.TIMEOUT);
        }

        @Override
        protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
            awsCredentials = credentials;
            clientConfiguration = config;
            final AmazonS3Client s3 = new AmazonS3Client(credentials, config);
            return s3;
        }

        @Override
        protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config) {
            awsCredentialsProvider = credentialsProvider;
            clientConfiguration = config;
            final AmazonS3Client s3 = new AmazonS3Client(credentialsProvider, config);
            return s3;
        }

        @Override
        public void onTrigger(final ProcessContext context, final ProcessSession session) {
        }
    };
    runner = TestRunners.newTestRunner(mockAwsProcessor);
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) List(java.util.List) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ProcessContext(org.apache.nifi.processor.ProcessContext) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Before(org.junit.Before)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)125 Test (org.junit.Test)75 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)26 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)20 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)19 AWSCredentials (com.amazonaws.auth.AWSCredentials)16 TestRunner (org.apache.nifi.util.TestRunner)15 ClientConfiguration (com.amazonaws.ClientConfiguration)12 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)12 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)8 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)7 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)7 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)7 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)7 ArrayList (java.util.ArrayList)7 Properties (java.util.Properties)7 Configuration (org.apache.hadoop.conf.Configuration)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7