Class AwsCredentialsProviderChain
- java.lang.Object
-
- software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain
-
- All Implemented Interfaces:
AutoCloseable
,AwsCredentialsProvider
,IdentityProvider<AwsCredentialsIdentity>
,ToCopyableBuilder<AwsCredentialsProviderChain.Builder,AwsCredentialsProviderChain>
,SdkAutoCloseable
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 theAutoCloseable.close()
on any credential providers in the chain that need to be closed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AwsCredentialsProviderChain.Builder
A builder for aAwsCredentialsProviderChain
that allows controlling its behavior.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AwsCredentialsProviderChain.Builder
builder()
Get a new builder for creating aAwsCredentialsProviderChain
.void
close()
static AwsCredentialsProviderChain
of(AwsCredentialsProvider... awsCredentialsProviders)
Create an AWS credentials provider chain with default configuration that checks the given credential providers.static AwsCredentialsProviderChain
of(IdentityProvider<? extends AwsCredentialsIdentity>... awsCredentialsProviders)
Create an AWS credentials provider chain with default configuration that checks the given credential providers.AwsCredentials
resolveCredentials()
ReturnsAwsCredentials
that can be used to authorize an AWS request.AwsCredentialsProviderChain.Builder
toBuilder()
String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
identityType, resolveIdentity
-
Methods inherited from interface software.amazon.awssdk.identity.spi.IdentityProvider
resolveIdentity, resolveIdentity
-
Methods inherited from interface software.amazon.awssdk.utils.builder.ToCopyableBuilder
copy
-
-
-
-
Method Detail
-
builder
public static AwsCredentialsProviderChain.Builder builder()
Get a new builder for creating aAwsCredentialsProviderChain
.
-
of
public static AwsCredentialsProviderChain of(AwsCredentialsProvider... awsCredentialsProviders)
Create an AWS credentials provider chain with default configuration that checks the given credential providers.- Parameters:
awsCredentialsProviders
- The credentials providers that should be checked for credentials, in the order they should be checked.- Returns:
- A credential provider chain that checks the provided credential providers in order.
-
of
public static AwsCredentialsProviderChain of(IdentityProvider<? extends AwsCredentialsIdentity>... awsCredentialsProviders)
Create an AWS credentials provider chain with default configuration that checks the given credential providers.- Parameters:
awsCredentialsProviders
- The credentials providers that should be checked for credentials, in the order they should be checked.- Returns:
- A credential provider chain that checks the provided credential providers in order.
-
resolveCredentials
public AwsCredentials resolveCredentials()
Description copied from interface:AwsCredentialsProvider
ReturnsAwsCredentials
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.
- Specified by:
resolveCredentials
in interfaceAwsCredentialsProvider
- Returns:
- AwsCredentials which the caller can use to authorize an AWS request.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSdkAutoCloseable
-
toBuilder
public AwsCredentialsProviderChain.Builder toBuilder()
- Specified by:
toBuilder
in interfaceToCopyableBuilder<AwsCredentialsProviderChain.Builder,AwsCredentialsProviderChain>
-
-