Package org.apache.nutch.protocol.httpclient

## Class HttpBasicAuthentication

- java.lang.Object
- - org.apache.nutch.protocol.httpclient.HttpBasicAuthentication

- All Implemented Interfaces:
    `Configurable`, `HttpAuthentication`

      public class HttpBasicAuthentication
      extends Object
      implements HttpAuthentication, Configurable

  Implementation of RFC 2617 Basic Authentication. Usernames and passwords are stored in standard Nutch configuration files using the following properties: http.auth.basic.<realm>.user http.auth.basic.<realm>.pass
  Author:
    Matt Tencati

- - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `HttpBasicAuthentication​(String challenge, Configuration conf)` | Construct an HttpBasicAuthentication for the given challenge parameters.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static HttpBasicAuthentication` | `getAuthentication​(String challenge, Configuration conf)` | This method is responsible for providing Basic authentication information.
    `static Pattern` | `getBasicPattern()` | Provides a pattern which can be used by an outside resource to determine if this class can provide credentials based on simple header information.
    `Configuration` | `getConf()` |
    `List<String>` | `getCredentials()` | Gets the Basic credentials generated by this HttpBasicAuthentication object
    `String` | `getRealm()` | Gets the realm attribute of the HttpBasicAuthentication object.
    `void` | `setConf​(Configuration conf)` |

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

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

- - ### Constructor Detail

    - #### HttpBasicAuthentication

          protected HttpBasicAuthentication​(String challenge,
                                            Configuration conf)
                                     throws HttpAuthenticationException

      Construct an HttpBasicAuthentication for the given challenge parameters. The challenge parameters are returned by the web server using a WWW-Authenticate header. This will typically be represented by single line of the form `WWW-Authenticate: Basic realm="myrealm"`
      Parameters:
        `challenge` - WWW-Authenticate header from web server
        `conf` - a populated `Configuration`
      Throws:
        `HttpAuthenticationException` - if the authentication fails or if the password or username is null

  - ### Method Detail

    - #### setConf

          public void setConf​(Configuration conf)

      Specified by:
        `setConf` in interface `Configurable`

    - #### getConf

          public Configuration getConf()

      Specified by:
        `getConf` in interface `Configurable`

    - #### getCredentials

          public List<String> getCredentials()

      Gets the Basic credentials generated by this HttpBasicAuthentication object
      Specified by:
        `getCredentials` in interface `HttpAuthentication`
      Returns:
        Credentials in the form of `Authorization: Basic <Base64 encoded userid:password>`

    - #### getRealm

          public String getRealm()

      Gets the realm attribute of the HttpBasicAuthentication object. This should have been supplied to the `getAuthentication(String, Configuration)` static method
      Specified by:
        `getRealm` in interface `HttpAuthentication`
      Returns:
        The realm

    - #### getAuthentication

          public static HttpBasicAuthentication getAuthentication​(String challenge,
                                                                  Configuration conf)

      This method is responsible for providing Basic authentication information. The method caches authentication information for each realm so that the required authentication information does not need to be regenerated for every request.
      Parameters:
        `challenge` - The challenge string provided by the webserver. This is the text which follows the WWW-Authenticate header, including the Basic tag.
        `conf` - a populated `Configuration`
      Returns:
        An HttpBasicAuthentication object or null if unable to generate appropriate credentials.

    - #### getBasicPattern

          public static final Pattern getBasicPattern()

      Provides a pattern which can be used by an outside resource to determine if this class can provide credentials based on simple header information. It does not calculate any information regarding realms or challenges.
      Returns:
        Returns a Pattern which will match a Basic WWW-Authenticate header.