org.apache.hc.client5.http.impl.auth

## Class AuthenticationHandler

- java.lang.Object
- - org.apache.hc.client5.http.impl.auth.AuthenticationHandler

Direct Known Subclasses:
  HttpAuthenticator

    @Internal
     @Contract(threading=STATELESS)
    public class AuthenticationHandler
    extends Object

Internal utility class that implements commons aspects of the client side HTTP authentication.

Since:
  5.4

### Constructor Summary

Constructors
Constructor and Description
`AuthenticationHandler()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addAuthResponse(HttpHost host, ChallengeType challengeType, HttpRequest request, AuthExchange authExchange, HttpContext context)` Generates a response to the authentication challenge based on the actual `AuthExchange` state and adds it to the given `HttpRequest` message .
`Map<String,AuthChallenge>` `extractChallengeMap(ChallengeType challengeType, HttpResponse response, HttpClientContext context)`
`boolean` `handleResponse(HttpHost host, ChallengeType challengeType, HttpResponse response, AuthenticationStrategy authStrategy, AuthExchange authExchange, HttpContext context)` Handles the response from the opposite endpoint and updates the `AuthExchange` state based on the challenge presented in the response message using the given `AuthenticationStrategy`.
`boolean` `isChallenged(HttpHost host, ChallengeType challengeType, HttpResponse response, AuthExchange authExchange, HttpContext context)` Determines whether the given response represents an authentication challenge, and updates the `AuthExchange` state.
`boolean` `isChallengeExpected(AuthExchange authExchange)` Determines if the scheme requires an auth challenge for responses that do not have a challenge HTTP code.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AuthenticationHandler

    public AuthenticationHandler()

### Method Detail

#### isChallenged

    public boolean isChallenged(HttpHost host,
                                ChallengeType challengeType,
                                HttpResponse response,
                                AuthExchange authExchange,
                                HttpContext context)

Determines whether the given response represents an authentication challenge, and updates the `AuthExchange` state.

Parameters:
  `host` - the hostname of the opposite endpoint.
  `challengeType` - the challenge type (target or proxy).
  `response` - the response message head.
  `authExchange` - the current authentication exchange state. Gets updated.
  `context` - the current execution context.
Returns:
  `true` if the response message represents an authentication challenge, `false` otherwise.

#### isChallengeExpected

    public boolean isChallengeExpected(AuthExchange authExchange)

Determines if the scheme requires an auth challenge for responses that do not have a challenge HTTP code. (i.e whether it needs a mutual authentication token)

#### extractChallengeMap

    public Map<String,AuthChallenge> extractChallengeMap(ChallengeType challengeType,
                                                         HttpResponse response,
                                                         HttpClientContext context)

#### handleResponse

    public boolean handleResponse(HttpHost host,
                                  ChallengeType challengeType,
                                  HttpResponse response,
                                  AuthenticationStrategy authStrategy,
                                  AuthExchange authExchange,
                                  HttpContext context)
                           throws AuthenticationException,
                                  MalformedChallengeException

Handles the response from the opposite endpoint and updates the `AuthExchange` state based on the challenge presented in the response message using the given `AuthenticationStrategy`.

Parameters:
  `host` - the hostname of the opposite endpoint.
  `challengeType` - the challenge type (target or proxy).
  `response` - the response message head.
  `authStrategy` - the authentication strategy.
  `authExchange` - the current authentication exchange state.
  `context` - the current execution context.
Returns:
  `true` if the request needs-to be re-sent, `false` if the authentication is complete (successful or not).
Throws:
  `AuthenticationException` - if the AuthScheme throws one. In most cases this indicates a client side problem, as final server error responses are simply returned.
  `MalformedChallengeException` - if the AuthScheme throws one. In most cases this indicates a client side problem, as final server error responses are simply returned.

#### addAuthResponse

    public void addAuthResponse(HttpHost host,
                                ChallengeType challengeType,
                                HttpRequest request,
                                AuthExchange authExchange,
                                HttpContext context)

Generates a response to the authentication challenge based on the actual `AuthExchange` state and adds it to the given `HttpRequest` message .

Parameters:
  `host` - the hostname of the opposite endpoint.
  `challengeType` - the challenge type (target or proxy).
  `request` - the request message head.
  `authExchange` - the current authentication exchange state.
  `context` - the current execution context.