Class TokenRequestBasedAuthenticatorImmutable<T extends AbstractToken,​R extends TokenServerResponse>

  • All Implemented Interfaces:
    Authenticator
    Direct Known Subclasses:
    IamRequestBasedAuthenticatorImmutable, MCSPV2Authenticator, TokenRequestBasedAuthenticator

    public abstract class TokenRequestBasedAuthenticatorImmutable<T extends AbstractToken,​R extends TokenServerResponse>
    extends AuthenticatorBase
    implements Authenticator
    This class serves as a common base class for Authenticator implementations that interact with a token service via a REST interface. This base class allows for the configuration of the following properties:
    • disableSSLVerification - a flag that indicates whether or not client-side SSL verification should be disabled.
    • headers - a Map of keys/values that will be set as HTTP headers on requests sent to the token service.
    • proxy - a java.net.Proxy instance that will be set on the OkHttpClient instance used to interact with the token service.
    • proxyAuthenticator - an okhttp3.Authenticator instance to be set on the OkHttpClient instance used to interact with the token service.
    • client - a fully-configured OkHttpClient instance to be used to interact with the token service.
    • Constructor Detail

      • TokenRequestBasedAuthenticatorImmutable

        public TokenRequestBasedAuthenticatorImmutable()
    • Method Detail

      • getClient

        public okhttp3.OkHttpClient getClient()
        Returns the OkHttpClient instance to be used when interacting with the token service.
        Returns:
        the client instance or null if a client instance has not yet been set
      • validate

        public abstract void validate()
        Validates the configuration properties associated with the Authenticator. Each concrete subclass must implement this method.
        Specified by:
        validate in interface Authenticator
      • authenticationType

        public abstract java.lang.String authenticationType()
        Returns the authentication type associated with this Authenticator. Each concrete subclass must implement this method.
        Specified by:
        authenticationType in interface Authenticator
        Returns:
        the authentication type
      • getDisableSSLVerification

        public boolean getDisableSSLVerification()
        Returns:
        the disableSSLVerification flag
      • getHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHeaders()
        Returns the set of user-supplied headers configured for this Authenticator.
        Returns:
        a Map containing the configured headers
      • getProxy

        public java.net.Proxy getProxy()
        Returns:
        the Proxy configured for this Authenticator
      • getProxyAuthenticator

        public okhttp3.Authenticator getProxyAuthenticator()
        Returns:
        the proxy authenticator configured for this Authenticator
      • authenticate

        public void authenticate​(okhttp3.Request.Builder builder)
        Authenticate the specified request by adding an Authorization header containing a "Bearer" access token.
        Specified by:
        authenticate in interface Authenticator
        Parameters:
        builder - the Request.Builder instance to authenticate
      • requestToken

        public abstract T requestToken()
        Builds and invokes the REST request to fetch a new token from the token service. Each concrete subclass must implement this method.
        Returns:
        the token object
      • getToken

        public java.lang.String getToken()
        This function returns the access token fetched from the token service. If no token currently exists or the current token has expired, a new token is fetched from the token service.
        Returns:
        the access token