Class SdkTokenProviderChain
- All Implemented Interfaces:
AutoCloseable
,SdkTokenProvider
,IdentityProvider<TokenIdentity>
,SdkAutoCloseable
SdkTokenProvider
implementation that chains together multiple token providers.
When a caller first requests token from this provider, it calls all the providers in the chain, in the original order specified, until one can provide a token, and then returns that token. If all of the token providers in the chain have been called, and none of them can provide token, then this class will throw an exception indicated that no token is available.
By default, this class will remember the first token provider in the chain that was able to provide tokens, and
will continue to use that provider when token is requested in the future, instead of traversing the chain each time.
This behavior can be controlled through the SdkTokenProviderChain.Builder.reuseLastProviderEnabled(Boolean)
method.
This chain implements AutoCloseable
. When closed, it will call the AutoCloseable.close()
on any token
providers in the chain that need to be closed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A builder for aSdkTokenProviderChain
that allows controlling its behavior. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Get a new builder for creating aSdkTokenProviderChain
.void
close()
static SdkTokenProviderChain
of
(SdkTokenProvider... sdkTokenProviders) Create a token provider chain with default configuration that checks the given token providers.static SdkTokenProviderChain
of
(IdentityProvider<? extends TokenIdentity>... sdkTokenProviders) Create a token provider chain with default configuration that checks the given token providers.Returns anSdkToken
that can be used to authorize a request.toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.awssdk.identity.spi.IdentityProvider
resolveIdentity, resolveIdentity
Methods inherited from interface software.amazon.awssdk.auth.token.credentials.SdkTokenProvider
identityType, resolveIdentity
-
Method Details
-
builder
Get a new builder for creating aSdkTokenProviderChain
. -
of
Create a token provider chain with default configuration that checks the given token providers.- Parameters:
sdkTokenProviders
- The token providers that should be checked for token, in the order they should be checked.- Returns:
- A token provider chain that checks the provided token providers in order.
-
of
public static SdkTokenProviderChain of(IdentityProvider<? extends TokenIdentity>... sdkTokenProviders) Create a token provider chain with default configuration that checks the given token providers.- Parameters:
sdkTokenProviders
- The token providers that should be checked for token, in the order they should be checked.- Returns:
- A token provider chain that checks the provided token providers in order.
-
resolveToken
Description copied from interface:SdkTokenProvider
Returns anSdkToken
that can be used to authorize a request. Each implementation of SdkTokenProvider can choose its own strategy for loading token. For example, an implementation might load token from an existing key management system, or load new token when token is refreshed.- Specified by:
resolveToken
in interfaceSdkTokenProvider
- Returns:
- AwsToken which the caller can use to authorize an AWS request using token authorization for a request.
-
close
public void close()Description copied from interface:SdkAutoCloseable
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSdkAutoCloseable
-
toString
-