Class SdkTokenProviderChain

  • All Implemented Interfaces:
    AutoCloseable, SdkTokenProvider, IdentityProvider<TokenIdentity>, SdkAutoCloseable

    public final class SdkTokenProviderChain
    extends Object
    implements SdkTokenProvider, SdkAutoCloseable
    An 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.

    • Method Detail

      • 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 an 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.
        Specified by:
        resolveToken in interface SdkTokenProvider
        Returns:
        AwsToken which the caller can use to authorize an AWS request using token authorization for a request.