AutoCloseable
, AwsCredentialsProvider
public final class AwsCredentialsProviderChain extends Object implements AwsCredentialsProvider, AutoCloseable
AwsCredentialsProvider
implementation that chains together multiple credentials providers.
When a caller first requests credentials from this provider, it calls all the providers in the chain, in the original order specified, until one can provide credentials, and then returns those credentials. If all of the credential providers in the chain have been called, and none of them can provide credentials, then this class will throw an exception indicated that no credentials are available.
By default, this class will remember the first credentials provider in the chain that was able to provide credentials, and
will continue to use that provider when credentials are requested in the future, instead of traversing the chain each time.
This behavior can be controlled through the AwsCredentialsProviderChain.Builder.reuseLastProviderEnabled(Boolean)
method.
This chain implements AutoCloseable
. When closed, it will call the AutoCloseable.close()
on any credential
providers in the chain that need to be closed.
Modifier and Type | Class | Description |
---|---|---|
static class |
AwsCredentialsProviderChain.Builder |
A builder for a
AwsCredentialsProviderChain that allows controlling its behavior. |
Modifier and Type | Method | Description |
---|---|---|
static AwsCredentialsProviderChain.Builder |
builder() |
Get a new builder for creating a
AwsCredentialsProviderChain . |
void |
close() |
|
AwsCredentials |
getCredentials() |
Returns
AwsCredentials that can be used to authorize an AWS request. |
static AwsCredentialsProviderChain |
of(AwsCredentialsProvider... awsCredentialsProviders) |
Create an AWS credentials provider chain with default configuration that checks the given credential providers.
|
String |
toString() |
public static AwsCredentialsProviderChain.Builder builder()
AwsCredentialsProviderChain
.public static AwsCredentialsProviderChain of(AwsCredentialsProvider... awsCredentialsProviders)
awsCredentialsProviders
- The credentials providers that should be checked for credentials, in the order they should
be checked.public AwsCredentials getCredentials()
AwsCredentialsProvider
AwsCredentials
that can be used to authorize an AWS request. Each implementation of AWSCredentialsProvider
can chose its own strategy for loading credentials. For example, an implementation might load credentials from an existing
key management system, or load new credentials when credentials are rotated.
If an error occurs during the loading of credentials or credentials could not be found, a runtime exception will be raised.
getCredentials
in interface AwsCredentialsProvider
public void close()
close
in interface AutoCloseable
Copyright © 2017 Amazon Web Services, Inc. All Rights Reserved.