Class BearerTokenAuthenticator

  • All Implemented Interfaces:
    Authenticator

    public class BearerTokenAuthenticator
    extends AuthenticatorBase
    implements Authenticator
    This class provides an Authenticator implementation that supports a user-supplied Bear Token value. The main purpose of this authenticator is to construct the Authorization header with the user-supplied token, then add the header to each outgoing REST API request.
    • Constructor Detail

      • BearerTokenAuthenticator

        public BearerTokenAuthenticator​(java.lang.String bearerToken)
        Construct a BearerTokenAuthenticator instance with the specified access token. The token value will be used to construct an Authorization header that will be included in outgoing REST API requests.
        Parameters:
        bearerToken - the access token value
      • BearerTokenAuthenticator

        public BearerTokenAuthenticator​(java.util.Map<java.lang.String,​java.lang.String> config)
        Deprecated.
        As of 9.7.0, use BearerTokenAuthenticator.fromConfiguration() instead.
        Construct a BearerTokenAuthenticator using properties retrieved from the specified Map.
        Parameters:
        config - a map containing the access token value
    • Method Detail

      • fromConfiguration

        public static BearerTokenAuthenticator fromConfiguration​(java.util.Map<java.lang.String,​java.lang.String> config)
        Construct a BearerTokenAuthenticator instance using properties retrieved from the specified Map.
        Parameters:
        config - a map containing the configuration properties
        Returns:
        the BearerTokenAuthenticator instance
      • validate

        public void validate()
        Description copied from interface: Authenticator
        Validates the current set of configuration information in the Authenticator.
        Specified by:
        validate in interface Authenticator
      • authenticationType

        public java.lang.String authenticationType()
        Description copied from interface: Authenticator
        Returns the authentication type associated with the Authenticator instance.
        Specified by:
        authenticationType in interface Authenticator
        Returns:
        a string representing the authentication type (e.g. "iam", "basic", "icp4d", etc.)
      • getBearerToken

        public java.lang.String getBearerToken()
        Returns:
        the access token configured for this Authenticator
      • setBearerToken

        public void setBearerToken​(java.lang.String bearerToken)
        Sets the bearer token value to be used by this Authenticator.
        Parameters:
        bearerToken - the new bearer token value
      • authenticate

        public void authenticate​(okhttp3.Request.Builder builder)
        This method is called to authenticate an outgoing REST API request. Here, we'll just set the Authorization header to provide the necessary authentication info.
        Specified by:
        authenticate in interface Authenticator
        Parameters:
        builder - the Request.Builder instance to authenticate