Class AwsCredentialsProviderChain
- All Implemented Interfaces:
AutoCloseable,AwsCredentialsProvider,IdentityProvider<AwsCredentialsIdentity>,ToCopyableBuilder<AwsCredentialsProviderChain.Builder,,AwsCredentialsProviderChain> SdkAutoCloseable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA builder for aAwsCredentialsProviderChainthat allows controlling its behavior. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Get a new builder for creating aAwsCredentialsProviderChain.voidclose()static AwsCredentialsProviderChainof(AwsCredentialsProvider... awsCredentialsProviders) Create an AWS credentials provider chain with default configuration that checks the given credential providers.static AwsCredentialsProviderChainof(IdentityProvider<? extends AwsCredentialsIdentity>... awsCredentialsProviders) Create an AWS credentials provider chain with default configuration that checks the given credential providers.ReturnsAwsCredentialsthat can be used to authorize an AWS request.Take this object and create a builder that contains all of the current property values of this object.toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
identityType, resolveIdentityMethods inherited from interface software.amazon.awssdk.identity.spi.IdentityProvider
resolveIdentity, resolveIdentityMethods inherited from interface software.amazon.awssdk.utils.builder.ToCopyableBuilder
copy
-
Method Details
-
builder
Get a new builder for creating aAwsCredentialsProviderChain. -
of
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
Description copied from interface:AwsCredentialsProviderReturnsAwsCredentialsthat 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:
resolveCredentialsin interfaceAwsCredentialsProvider- Returns:
- AwsCredentials which the caller can use to authorize an AWS request.
-
close
public void close()Description copied from interface:SdkAutoCloseable- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSdkAutoCloseable
-
toString
-
toBuilder
Description copied from interface:ToCopyableBuilderTake this object and create a builder that contains all of the current property values of this object.- Specified by:
toBuilderin interfaceToCopyableBuilder<AwsCredentialsProviderChain.Builder,AwsCredentialsProviderChain> - Returns:
- a builder for type T
-