Class SdkTokenProviderChain
- java.lang.Object
-
- software.amazon.awssdk.auth.token.credentials.SdkTokenProviderChain
-
- All Implemented Interfaces:
AutoCloseable
,SdkTokenProvider
,IdentityProvider<TokenIdentity>
,SdkAutoCloseable
public final class SdkTokenProviderChain extends Object implements SdkTokenProvider, SdkAutoCloseable
AnSdkTokenProvider
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 theAutoCloseable.close()
on any token providers in the chain that need to be closed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SdkTokenProviderChain.Builder
A builder for aSdkTokenProviderChain
that allows controlling its behavior.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SdkTokenProviderChain.Builder
builder()
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.SdkToken
resolveToken()
Returns anSdkToken
that can be used to authorize a request.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.identity.spi.IdentityProvider
resolveIdentity, resolveIdentity
-
Methods inherited from interface software.amazon.awssdk.auth.token.credentials.SdkTokenProvider
identityType, resolveIdentity
-
-
-
-
Method Detail
-
builder
public static SdkTokenProviderChain.Builder builder()
Get a new builder for creating aSdkTokenProviderChain
.
-
of
public static SdkTokenProviderChain of(SdkTokenProvider... 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.
-
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
public SdkToken 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()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSdkAutoCloseable
-
-