public final class SdkTokenProviderChain extends Object implements SdkTokenProvider, 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.
Modifier and Type | Class and Description |
---|---|
static interface |
SdkTokenProviderChain.Builder
A builder for a
SdkTokenProviderChain that allows controlling its behavior. |
Modifier and Type | Method and Description |
---|---|
static SdkTokenProviderChain.Builder |
builder()
Get a new builder for creating a
SdkTokenProviderChain . |
void |
close() |
static SdkTokenProviderChain |
of(SdkTokenProvider... sdkTokenProviders)
Create an AWS token provider chain with default configuration that checks the given token providers.
|
SdkToken |
resolveToken()
Returns an
SdkToken that can be used to authorize a request. |
String |
toString() |
public static SdkTokenProviderChain.Builder builder()
SdkTokenProviderChain
.public static SdkTokenProviderChain of(SdkTokenProvider... sdkTokenProviders)
sdkTokenProviders
- The token providers that should be checked for token, in the order they should
be checked.public SdkToken resolveToken()
SdkTokenProvider
SdkToken
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.resolveToken
in interface SdkTokenProvider
public void close()
close
in interface AutoCloseable
close
in interface SdkAutoCloseable
Copyright © 2023. All rights reserved.