org.apache.hc.core5.http.nio.support

## Class AbstractAsyncServerAuthFilter<T>

- java.lang.Object
- - org.apache.hc.core5.http.nio.support.AbstractAsyncServerAuthFilter<T>

- Type Parameters:
    `T` - authorization token representation.
  All Implemented Interfaces:
    AsyncFilterHandler

      @Contract(threading=STATELESS)
      public abstract class AbstractAsyncServerAuthFilter<T>
      extends Object
      implements AsyncFilterHandler

  Abstract asynchronous HTTP request filter that implements standard HTTP authentication handshake.
  Since:
    5.0

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractAsyncServerAuthFilter(boolean respondImmediately)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract boolean` | `authenticate(T challengeResponse, URIAuthority authority, String requestUri, HttpContext context)` Authenticates the client using the authentication token sent by the client as a response to an authentication challenge.
    `protected abstract String` | `generateChallenge(T challengeResponse, URIAuthority authority, String requestUri, HttpContext context)` Generates an authentication challenge in case of unsuccessful authentication.
    `protected AsyncEntityProducer` | `generateResponseContent(HttpResponse unauthorized)` Generates response body for UNAUTHORIZED response.
    `AsyncDataConsumer` | `handle(HttpRequest request, EntityDetails entityDetails, HttpContext context, AsyncFilterChain.ResponseTrigger responseTrigger, AsyncFilterChain chain)` Processes the incoming HTTP request and if processing has been completed submits a final response to the client.
    `protected abstract T` | `parseChallengeResponse(String authorizationValue, HttpContext context)` Parses authorization header value into an authentication token sent by the client as a response to an authentication challenge.

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

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

- - ### Constructor Detail

    - #### AbstractAsyncServerAuthFilter

          protected AbstractAsyncServerAuthFilter(boolean respondImmediately)

  - ### Method Detail

    - #### parseChallengeResponse

          protected abstract T parseChallengeResponse(String authorizationValue,
                                                      HttpContext context)
                                               throws HttpException

      Parses authorization header value into an authentication token sent by the client as a response to an authentication challenge.
      Parameters:
        `authorizationValue` - the authorization header value.
        `context` - the actual execution context.
      Returns:
        authorization token
      Throws:
        `HttpException`

    - #### authenticate

          protected abstract boolean authenticate(T challengeResponse,
                                                  URIAuthority authority,
                                                  String requestUri,
                                                  HttpContext context)

      Authenticates the client using the authentication token sent by the client as a response to an authentication challenge.
      Parameters:
        `challengeResponse` - the authentication token sent by the client as a response to an authentication challenge.
        `authority` - the URI authority.
        `requestUri` - the request URI.
        `context` - the actual execution context.
      Returns:
        `true` if the client could be successfully authenticated `false` otherwise.

    - #### generateChallenge

          protected abstract String generateChallenge(T challengeResponse,
                                                      URIAuthority authority,
                                                      String requestUri,
                                                      HttpContext context)

      Generates an authentication challenge in case of unsuccessful authentication.
      Parameters:
        `challengeResponse` - the authentication token sent by the client as a response to an authentication challenge or `null` if the client has not sent any.
        `authority` - the URI authority.
        `requestUri` - the request URI.
        `context` - the actual execution context.
      Returns:
        an authorization challenge value.

    - #### generateResponseContent

          protected AsyncEntityProducer generateResponseContent(HttpResponse unauthorized)

      Generates response body for UNAUTHORIZED response.
      Parameters:
        `unauthorized` - the response to return as a result of authentication failure.
      Returns:
        the response content entity.

    - #### handle

          public final AsyncDataConsumer handle(HttpRequest request,
                                                EntityDetails entityDetails,
                                                HttpContext context,
                                                AsyncFilterChain.ResponseTrigger responseTrigger,
                                                AsyncFilterChain chain)
                                         throws HttpException,
                                                IOException

      Description copied from interface: `AsyncFilterHandler`
      Processes the incoming HTTP request and if processing has been completed submits a final response to the client. The handler can choose to send response messages immediately inside the call or asynchronously at some later point. The handler must not use the response trigger after passing control to the next filter with the `AsyncFilterChain.proceed(HttpRequest, EntityDetails, HttpContext, AsyncFilterChain.ResponseTrigger)` method.
      Specified by:
        `handle` in interface `AsyncFilterHandler`
      Parameters:
        `request` - the actual request head.
        `entityDetails` - the request entity details or `null` if the request does not enclose an entity.
        `context` - the actual execution context.
        `responseTrigger` - the response trigger.
        `chain` - the next element in the request processing chain.
      Returns:
        the data consumer to be used to process incoming request data. It is expected to be `null` if entityDetails parameter is `null`.
      Throws:
        `HttpException`
        `IOException`

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.