List of usage examples for com.amazonaws.auth AWSCredentialsProviderChain setReuseLastProvider
public void setReuseLastProvider(boolean b)
From source file:com.thinkbiganalytics.kylo.catalog.aws.S3FileSystemProvider.java
License:Apache License
/** * Creates an S3 client with the standard credential providers. *///from w w w . j a va2 s . co m @VisibleForTesting protected AmazonS3 createS3Client(@Nonnull final URI uri, @Nonnull final Configuration conf) { // Create list of credential providers final List<AWSCredentialsProvider> credentials = new ArrayList<>(); getCustomCredentialsProvider(uri, conf).ifPresent(credentials::add); getBasicCredentialsProvider(uri, conf).ifPresent(credentials::add); credentials.add(InstanceProfileCredentialsProvider.getInstance()); // Create client final AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(credentials); chain.setReuseLastProvider(true); return AmazonS3ClientBuilder.standard().withCredentials(chain).build(); }
From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java
License:Open Source License
protected AWSCredentialsProvider getAWSCredentialsProvider(Configuration conf) { List<AWSCredentialsProvider> providersList = new ArrayList<>(); // try to load custom credential provider, fail if a provider is specified but cannot be // initialized String providerClass = conf.get(DynamoDBConstants.CUSTOM_CREDENTIALS_PROVIDER_CONF); if (!Strings.isNullOrEmpty(providerClass)) { try {//from w w w. j a v a2s . c o m providersList.add( (AWSCredentialsProvider) ReflectionUtils.newInstance(Class.forName(providerClass), conf)); } catch (ClassNotFoundException e) { throw new RuntimeException("Custom AWSCredentialsProvider not found: " + providerClass, e); } } // try to fetch credentials from core-site String accessKey = conf.get(DYNAMODB_CREDENTIAL_PAIR_NAME.getAccessKeyName()); String secretKey; if (Strings.isNullOrEmpty(accessKey)) { accessKey = conf.get(DEFAULT_CREDENTIAL_PAIR_NAME.getAccessKeyName()); secretKey = conf.get(DEFAULT_CREDENTIAL_PAIR_NAME.getSecretKeyName()); } else { secretKey = conf.get(DYNAMODB_CREDENTIAL_PAIR_NAME.getSecretKeyName()); } if (Strings.isNullOrEmpty(accessKey) || Strings.isNullOrEmpty(secretKey)) { providersList.add(new InstanceProfileCredentialsProvider()); } else { final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); providersList.add(new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return credentials; } @Override public void refresh() { } }); } AWSCredentialsProvider[] providerArray = providersList .toArray(new AWSCredentialsProvider[providersList.size()]); AWSCredentialsProviderChain providerChain = new AWSCredentialsProviderChain(providerArray); providerChain.setReuseLastProvider(true); return providerChain; }
From source file:org.springframework.cloud.aws.core.credentials.CredentialsProviderFactoryBean.java
License:Apache License
@Override protected AWSCredentialsProvider createInstance() throws Exception { AWSCredentialsProviderChain awsCredentialsProviderChain; if (this.delegates.isEmpty()) { awsCredentialsProviderChain = new DefaultAWSCredentialsProviderChain(); } else {//from w w w .ja va2s . c om awsCredentialsProviderChain = new AWSCredentialsProviderChain( this.delegates.toArray(new AWSCredentialsProvider[this.delegates.size()])); } awsCredentialsProviderChain.setReuseLastProvider(false); return awsCredentialsProviderChain; }