Search in sources :

Example 1 with StaticCredentialsProvider

use of com.amazonaws.internal.StaticCredentialsProvider in project nifi by apache.

the class AccessKeyPairCredentialsStrategy method getCredentialsProvider.

@Override
public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) {
    String accessKey = properties.get(CredentialPropertyDescriptors.ACCESS_KEY);
    String secretKey = properties.get(CredentialPropertyDescriptors.SECRET_KEY);
    BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
    return new StaticCredentialsProvider(creds);
}
Also used : StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with StaticCredentialsProvider

use of com.amazonaws.internal.StaticCredentialsProvider in project components by Talend.

the class S3Connection method createClient.

public static AmazonS3 createClient(S3OutputProperties properties) {
    S3DatasetProperties data_set = properties.getDatasetProperties();
    S3DatastoreProperties data_store = properties.getDatasetProperties().getDatastoreProperties();
    com.amazonaws.auth.AWSCredentials credentials = new com.amazonaws.auth.BasicAWSCredentials(data_store.accessKey.getValue(), data_store.secretKey.getValue());
    Region region = RegionUtils.getRegion(data_set.region.getValue().getValue());
    Boolean clientSideEnc = data_set.encryptDataInMotion.getValue();
    AmazonS3 conn = null;
    if (clientSideEnc != null && clientSideEnc) {
        String kms_cmk = data_set.kmsForDataInMotion.getValue();
        KMSEncryptionMaterialsProvider encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider(kms_cmk);
        conn = new AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, new CryptoConfiguration().withAwsKmsRegion(region));
    } else {
        AWSCredentialsProvider basicCredentialsProvider = new StaticCredentialsProvider(credentials);
        conn = new AmazonS3Client(basicCredentialsProvider);
    }
    conn.setRegion(region);
    return conn;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3EncryptionClient(com.amazonaws.services.s3.AmazonS3EncryptionClient) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) CryptoConfiguration(com.amazonaws.services.s3.model.CryptoConfiguration) S3DatasetProperties(org.talend.components.simplefileio.s3.S3DatasetProperties) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Region(com.amazonaws.regions.Region) S3DatastoreProperties(org.talend.components.simplefileio.s3.S3DatastoreProperties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 3 with StaticCredentialsProvider

use of com.amazonaws.internal.StaticCredentialsProvider in project herd by FINRAOS.

the class S3DaoTest method testGetAWSCredentialsProviderAssertStaticCredentialsSet.

@Test
public void testGetAWSCredentialsProviderAssertStaticCredentialsSet() {
    S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
    S3Operations mockS3Operations = mock(S3Operations.class);
    ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
    try {
        String s3BucketName = "s3BucketName";
        String s3KeyPrefix = "s3KeyPrefix";
        String s3AccessKey = "s3AccessKey";
        String s3SecretKey = "s3SecretKey";
        S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
        s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
        s3FileTransferRequestParamsDto.setAwsAccessKeyId(s3AccessKey);
        s3FileTransferRequestParamsDto.setAwsSecretKey(s3SecretKey);
        when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {

            @SuppressWarnings("unchecked")
            @Override
            public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
                AmazonS3Client amazonS3Client = invocation.getArgument(1);
                AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) ReflectionTestUtils.getField(amazonS3Client, "awsCredentialsProvider");
                List<AWSCredentialsProvider> credentialsProviders = (List<AWSCredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProviderChain, "credentialsProviders");
                // Expect 2 providers: the static provider, and the default provider
                assertEquals(2, credentialsProviders.size());
                // Only verify the static value
                assertEquals(StaticCredentialsProvider.class, credentialsProviders.get(0).getClass());
                StaticCredentialsProvider staticCredentialsProvider = (StaticCredentialsProvider) credentialsProviders.get(0);
                assertEquals(s3AccessKey, staticCredentialsProvider.getCredentials().getAWSAccessKeyId());
                assertEquals(s3SecretKey, staticCredentialsProvider.getCredentials().getAWSSecretKey());
                return new PutObjectResult();
            }
        });
        s3Dao.createDirectory(s3FileTransferRequestParamsDto);
    } finally {
        ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
    }
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSCredentialsProviderChain(com.amazonaws.auth.AWSCredentialsProviderChain) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) ArrayList(java.util.ArrayList) HerdAWSCredentialsProvider(org.finra.herd.model.dto.HerdAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 4 with StaticCredentialsProvider

use of com.amazonaws.internal.StaticCredentialsProvider in project herd by FINRAOS.

the class S3DaoImpl method getAWSCredentialsProvider.

/**
 * <p> Gets the {@link AWSCredentialsProvider} based on the credentials in the given parameters. </p> <p> Returns {@link DefaultAWSCredentialsProviderChain}
 * if either access or secret key is {@code null}. Otherwise returns a {@link StaticCredentialsProvider} with the credentials. </p>
 *
 * @param params - Access parameters
 *
 * @return AWS credentials provider implementation
 */
private AWSCredentialsProvider getAWSCredentialsProvider(S3FileTransferRequestParamsDto params) {
    List<AWSCredentialsProvider> providers = new ArrayList<>();
    String accessKey = params.getAwsAccessKeyId();
    String secretKey = params.getAwsSecretKey();
    if (accessKey != null && secretKey != null) {
        providers.add(new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
    }
    for (HerdAWSCredentialsProvider herdAWSCredentialsProvider : params.getAdditionalAwsCredentialsProviders()) {
        providers.add(new HerdAwsCredentialsProviderWrapper(herdAWSCredentialsProvider));
    }
    providers.add(new DefaultAWSCredentialsProviderChain());
    return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[providers.size()]));
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) HerdAWSCredentialsProvider(org.finra.herd.model.dto.HerdAWSCredentialsProvider) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) ArrayList(java.util.ArrayList) HerdAWSCredentialsProvider(org.finra.herd.model.dto.HerdAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSCredentialsProviderChain(com.amazonaws.auth.AWSCredentialsProviderChain)

Example 5 with StaticCredentialsProvider

use of com.amazonaws.internal.StaticCredentialsProvider 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)

Aggregations

StaticCredentialsProvider (com.amazonaws.internal.StaticCredentialsProvider)7 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)4 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HerdAWSCredentialsProvider (org.finra.herd.model.dto.HerdAWSCredentialsProvider)2 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 Region (com.amazonaws.regions.Region)1 AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)1 PutRecordsRequest (com.amazonaws.services.kinesis.model.PutRecordsRequest)1 PutRecordsRequestEntry (com.amazonaws.services.kinesis.model.PutRecordsRequestEntry)1 PutRecordsResult (com.amazonaws.services.kinesis.model.PutRecordsResult)1 PutRecordsResultEntry (com.amazonaws.services.kinesis.model.PutRecordsResultEntry)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3EncryptionClient (com.amazonaws.services.s3.AmazonS3EncryptionClient)1 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)1 CryptoConfiguration (com.amazonaws.services.s3.model.CryptoConfiguration)1