Class AuthorizationChallengeHandler


  • public class AuthorizationChallengeHandler
    extends java.lang.Object
    This class handles Basic and Digest authorization challenges, complying to RFC 2617 and RFC 7616.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AUTHENTICATION_INFO
      Header representing additional information a server is expecting during future authentication requests.
      static java.lang.String AUTHORIZATION
      Header representing the authorization the client is presenting to a server.
      static java.lang.String PROXY_AUTHENTICATE
      Header representing a proxy server requesting authentication.
      static java.lang.String PROXY_AUTHENTICATION_INFO
      Header representing additional information a proxy server is expecting during future authentication requests.
      static java.lang.String PROXY_AUTHORIZATION
      Header representing the authorization the client is presenting to a proxy server.
      static java.lang.String WWW_AUTHENTICATE
      Header representing a server requesting authentication.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String attemptToPipelineAuthorization​(java.lang.String method, java.lang.String uri, com.azure.android.core.http.util.AuthorizationChallengeHandler.Supplier<byte[]> entityBodySupplier)
      Attempts to pipeline requests by applying the most recent authorization type used to create an authorization header.
      void consumeAuthenticationInfoHeader​(java.util.Map<java.lang.String,​java.lang.String> authenticationInfoMap)
      Consumes either the 'Authentication-Info' or 'Proxy-Authentication-Info' header returned in a response from a server.
      java.lang.String handleBasic()
      Handles Basic authentication challenges.
      java.lang.String handleDigest​(java.lang.String method, java.lang.String uri, java.util.List<java.util.Map<java.lang.String,​java.lang.String>> challenges, com.azure.android.core.http.util.AuthorizationChallengeHandler.Supplier<byte[]> entityBodySupplier)
      Handles Digest authentication challenges.
      static java.util.Map<java.lang.String,​java.lang.String> parseAuthenticationOrAuthorizationHeader​(java.lang.String header)
      Parses the Authorization or Authentication header into its key-value pairs.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • WWW_AUTHENTICATE

        public static final java.lang.String WWW_AUTHENTICATE
        Header representing a server requesting authentication.
        See Also:
        Constant Field Values
      • PROXY_AUTHENTICATE

        public static final java.lang.String PROXY_AUTHENTICATE
        Header representing a proxy server requesting authentication.
        See Also:
        Constant Field Values
      • AUTHORIZATION

        public static final java.lang.String AUTHORIZATION
        Header representing the authorization the client is presenting to a server.
        See Also:
        Constant Field Values
      • PROXY_AUTHORIZATION

        public static final java.lang.String PROXY_AUTHORIZATION
        Header representing the authorization the client is presenting to a proxy server.
        See Also:
        Constant Field Values
      • AUTHENTICATION_INFO

        public static final java.lang.String AUTHENTICATION_INFO
        Header representing additional information a server is expecting during future authentication requests.
        See Also:
        Constant Field Values
      • PROXY_AUTHENTICATION_INFO

        public static final java.lang.String PROXY_AUTHENTICATION_INFO
        Header representing additional information a proxy server is expecting during future authentication requests.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AuthorizationChallengeHandler

        public AuthorizationChallengeHandler​(java.lang.String username,
                                             java.lang.String password)
        Creates an AuthorizationChallengeHandler using the username and password to respond to authentication challenges.
        Parameters:
        username - Username used to response to authorization challenges.
        password - Password used to respond to authorization challenges.
        Throws:
        java.lang.NullPointerException - If username or password are null.
    • Method Detail

      • handleBasic

        public final java.lang.String handleBasic()
        Handles Basic authentication challenges.
        Returns:
        Authorization header for Basic authentication challenges.
      • handleDigest

        public final java.lang.String handleDigest​(java.lang.String method,
                                                   java.lang.String uri,
                                                   java.util.List<java.util.Map<java.lang.String,​java.lang.String>> challenges,
                                                   com.azure.android.core.http.util.AuthorizationChallengeHandler.Supplier<byte[]> entityBodySupplier)
        Handles Digest authentication challenges.
        Parameters:
        method - HTTP method being used in the request.
        uri - Relative URI for the request.
        challenges - List of challenges that the server returned for the client to choose from and use when creating the authorization header.
        entityBodySupplier - Supplies the request entity body, used to compute the hash of the body when using "qop=auth-int".
        Returns:
        Authorization header for Digest authentication challenges.
      • attemptToPipelineAuthorization

        public final java.lang.String attemptToPipelineAuthorization​(java.lang.String method,
                                                                     java.lang.String uri,
                                                                     com.azure.android.core.http.util.AuthorizationChallengeHandler.Supplier<byte[]> entityBodySupplier)
        Attempts to pipeline requests by applying the most recent authorization type used to create an authorization header.
        Parameters:
        method - HTTP method being used in the request.
        uri - Relative URI for the request.
        entityBodySupplier - Supplies the request entity body, used to compute the hash of the body when using "qop=auth-int".
        Returns:
        A preemptive authorization header for a potential Digest authentication challenge.
      • consumeAuthenticationInfoHeader

        public final void consumeAuthenticationInfoHeader​(java.util.Map<java.lang.String,​java.lang.String> authenticationInfoMap)
        Consumes either the 'Authentication-Info' or 'Proxy-Authentication-Info' header returned in a response from a server. This header is used by the server to communicate information about the successful authentication of the client, this header may be returned at any time by the server.

        See RFC 7615 for more information about these headers.

        Parameters:
        authenticationInfoMap - Either 'Authentication-Info' or 'Proxy-Authentication-Info' header returned from the server split into its key-value pair pieces.
      • parseAuthenticationOrAuthorizationHeader

        public static java.util.Map<java.lang.String,​java.lang.String> parseAuthenticationOrAuthorizationHeader​(java.lang.String header)
        Parses the Authorization or Authentication header into its key-value pairs.

        This will remove quotes on quoted string values.

        Parameters:
        header - Authorization or Authentication header.
        Returns:
        The Authorization or Authentication header split into its key-value pairs.