public final class AwsCredentialsProviderChain extends Object implements AwsCredentialsProvider, SdkAutoCloseable, ToCopyableBuilder<AwsCredentialsProviderChain.Builder,AwsCredentialsProviderChain>
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 and Description |
---|---|
static interface |
AwsCredentialsProviderChain.Builder
A builder for a
AwsCredentialsProviderChain that allows controlling its behavior. |
Modifier and Type | Method and Description |
---|---|
static AwsCredentialsProviderChain.Builder |
builder()
Get a new builder for creating a
AwsCredentialsProviderChain . |
void |
close() |
static AwsCredentialsProviderChain |
of(AwsCredentialsProvider... awsCredentialsProviders)
Create an AWS credentials provider chain with default configuration that checks the given credential providers.
|
AwsCredentials |
resolveCredentials()
Returns
AwsCredentials that can be used to authorize an AWS request. |
AwsCredentialsProviderChain.Builder |
toBuilder() |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
copy
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 resolveCredentials()
AwsCredentialsProvider
AwsCredentials
that can be used to authorize an AWS request. Each implementation of AWSCredentialsProvider
can choose 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.
resolveCredentials
in interface AwsCredentialsProvider
public void close()
close
in interface AutoCloseable
close
in interface SdkAutoCloseable
public AwsCredentialsProviderChain.Builder toBuilder()
toBuilder
in interface ToCopyableBuilder<AwsCredentialsProviderChain.Builder,AwsCredentialsProviderChain>
Copyright © 2023. All rights reserved.