org.apache.http.impl.auth

## Class BasicScheme

- java.lang.Object
- - org.apache.http.impl.auth.AuthSchemeBase
  - - org.apache.http.impl.auth.RFC2617Scheme
    - - org.apache.http.impl.auth.BasicScheme

- All Implemented Interfaces:
    Serializable, AuthScheme, ContextAwareAuthScheme

      public class BasicScheme
      extends RFC2617Scheme

  Basic authentication scheme as defined in RFC 2617.
  Since:
    4.0
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.apache.http.impl.auth.AuthSchemeBase

      `challengeState`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicScheme()`
    `BasicScheme(ChallengeState challengeState)` Deprecated. (4.3) do not use.
    `BasicScheme(Charset credentialsCharset)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.apache.http.Header` | `authenticate(Credentials credentials, org.apache.http.HttpRequest request)` Deprecated. (4.2) Use `ContextAwareAuthScheme.authenticate( Credentials, HttpRequest, org.apache.http.protocol.HttpContext)`
    `org.apache.http.Header` | `authenticate(Credentials credentials, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)` Produces basic authorization header for the given set of `Credentials`.
    `static org.apache.http.Header` | `authenticate(Credentials credentials, String charset, boolean proxy)` Deprecated. (4.3) use `authenticate(Credentials, HttpRequest, HttpContext)`.
    `String` | `getSchemeName()` Returns textual designation of the basic authentication scheme.
    `boolean` | `isComplete()` Tests if the Basic authentication process has been completed.
    `boolean` | `isConnectionBased()` Returns `false`.
    `void` | `processChallenge(org.apache.http.Header header)` Processes the Basic challenge.
    `String` | `toString()`

    - ### Methods inherited from class org.apache.http.impl.auth.RFC2617Scheme

      `getCredentialsCharset, getParameter, getParameters, getRealm, parseChallenge`

    - ### Methods inherited from class org.apache.http.impl.auth.AuthSchemeBase

      `getChallengeState, isProxy`

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

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

- - ### Constructor Detail

    - #### BasicScheme

          public BasicScheme(Charset credentialsCharset)

      Since:
        4.3

    - #### BasicScheme

          @Deprecated
          public BasicScheme(ChallengeState challengeState)

      Deprecated. (4.3) do not use.
      Creates an instance of `BasicScheme` with the given challenge state.
      Since:
        4.2

    - #### BasicScheme

          public BasicScheme()

  - ### Method Detail

    - #### getSchemeName

          public String getSchemeName()

      Returns textual designation of the basic authentication scheme.
      Returns:
        `basic`

    - #### processChallenge

          public void processChallenge(org.apache.http.Header header)
                                throws MalformedChallengeException

      Processes the Basic challenge.
      Specified by:
        `processChallenge` in interface `AuthScheme`
      Overrides:
        `processChallenge` in class `AuthSchemeBase`
      Parameters:
        `header` - the challenge header
      Throws:
        `MalformedChallengeException` - is thrown if the authentication challenge is malformed

    - #### isComplete

          public boolean isComplete()

      Tests if the Basic authentication process has been completed.
      Returns:
        `true` if Basic authorization has been processed, `false` otherwise.

    - #### isConnectionBased

          public boolean isConnectionBased()

      Returns `false`. Basic authentication scheme is request based.
      Returns:
        `false`.

    - #### authenticate

          @Deprecated
          public org.apache.http.Header authenticate(Credentials credentials,
                                                       org.apache.http.HttpRequest request)
                                              throws AuthenticationException

      Deprecated. (4.2) Use `ContextAwareAuthScheme.authenticate( Credentials, HttpRequest, org.apache.http.protocol.HttpContext)`
      Description copied from interface: `AuthScheme`
      Produces an authorization string for the given set of `Credentials`.
      Parameters:
        `credentials` - The set of credentials to be used for athentication
        `request` - The request being authenticated
      Returns:
        the authorization string
      Throws:
        `AuthenticationException` - if authorization string cannot be generated due to an authentication failure

    - #### authenticate

          public org.apache.http.Header authenticate(Credentials credentials,
                                            org.apache.http.HttpRequest request,
                                            org.apache.http.protocol.HttpContext context)
                                              throws AuthenticationException

      Produces basic authorization header for the given set of `Credentials`.
      Specified by:
        `authenticate` in interface `ContextAwareAuthScheme`
      Overrides:
        `authenticate` in class `AuthSchemeBase`
      Parameters:
        `credentials` - The set of credentials to be used for authentication
        `request` - The request being authenticated
        `context` - HTTP context
      Returns:
        a basic authorization string
      Throws:
        `InvalidCredentialsException` - if authentication credentials are not valid or not applicable for this authentication scheme
        `AuthenticationException` - if authorization string cannot be generated due to an authentication failure

    - #### authenticate

          @Deprecated
          public static org.apache.http.Header authenticate(Credentials credentials,
                                                       String charset,
                                                       boolean proxy)

      Deprecated. (4.3) use `authenticate(Credentials, HttpRequest, HttpContext)`.
      Returns a basic `Authorization` header value for the given `Credentials` and charset.
      Parameters:
        `credentials` - The credentials to encode.
        `charset` - The charset to use for encoding the credentials
      Returns:
        a basic authorization header

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `AuthSchemeBase`

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