Class HttpAuthConfig

java.lang.Object
com.norconex.collector.http.fetch.impl.HttpAuthConfig
All Implemented Interfaces:
IXMLConfigurable

public class HttpAuthConfig extends Object implements IXMLConfigurable

Generic HTTP Fetcher authentication configuration.

XML configuration usage:


<method>[form|basic|digest|ntlm|spnego|kerberos]</method>
<!-- These apply to any authentication mechanism -->
<credentials/>
<!-- These apply to FORM authentication -->
<formUsernameField>...</formUsernameField>
<formPasswordField>...</formPasswordField>
<url>
  (Either a login form's action target URL or the URL of a page containing
   a login form if a "formSelector" is specified.)
</url>
<formCharset>...</formCharset>
<!-- Extra form parameters required to authenticate (since 2.8.0) -->
<formParams>
  <param
      name="(param name)">
    (param value)
  </param>
  <!-- You can repeat this param tag as needed. -->
</formParams>
<formSelector>
  (CSS selector identifying the login page. E.g., "form")
</formSelector>
<!-- These apply to both BASIC and DIGEST authentication -->
<host/>
<realm>...</realm>
<!-- This applies to BASIC authentication -->
<preemptive>[false|true]</preemptive>
<!-- These apply to NTLM authentication -->
<host/>
<workstation>...</workstation>
<domain>...</domain>

The above XML configurable options can be nested in a supporting parent tag of any name. The expected parent tag name is defined by the consuming classes (e.g. "authentication").

Since:
3.0.0
Author:
Pascal Essiembre
  • Field Details

  • Constructor Details

    • HttpAuthConfig

      public HttpAuthConfig()
  • Method Details

    • getMethod

      public String getMethod()
      Gets the authentication method.
      Returns:
      authentication method
    • setMethod

      public void setMethod(String method)
      Sets the authentication method.

      Valid values are (case insensitive):
      • form
      • basic
      • digest
      • ntlm
      Experimental (not fully tested, please report):
      • spnego
      • kerberos
      Parameters:
      method - authentication method
    • getFormUsernameField

      public String getFormUsernameField()
      Gets the name of the HTML field where the username is set. This is used only for "form" authentication.
      Returns:
      username name of the HTML field
    • setFormUsernameField

      public void setFormUsernameField(String formUsernameField)
      Sets the name of the HTML field where the username is set. This is used only for "form" authentication.
      Parameters:
      formUsernameField - name of the HTML field
    • getFormPasswordField

      public String getFormPasswordField()
      Gets the name of the HTML field where the password is set. This is used only for "form" authentication.
      Returns:
      name of the HTML field
    • setFormPasswordField

      public void setFormPasswordField(String formPasswordField)
      Sets the name of the HTML field where the password is set. This is used only for "form" authentication.
      Parameters:
      formPasswordField - name of the HTML field
    • getCredentials

      public Credentials getCredentials()
    • setCredentials

      public void setCredentials(Credentials authCredentials)
    • getUrl

      public String getUrl()
      Gets the URL for "form" authentication. The username and password will be POSTed to this URL. This is used only for "form" authentication.
      Returns:
      "form" authentication URL
    • setUrl

      public void setUrl(String url)
      Sets the URL for "form" authentication. The username and password will be POSTed to this URL. This is used only for "form" authentication.
      Parameters:
      url - "form" authentication URL
    • getHost

      public Host getHost()
      Gets the host for the current authentication scope. null means any host names for the scope. Used for BASIC and DIGEST authentication.
      Returns:
      host for the scope
    • setHost

      public void setHost(Host host)
      Sets the host for the current authentication scope. Setting this to null (default value) indicates "any host" for the scope. Used for BASIC and DIGEST authentication.
      Parameters:
      host - host for the scope
    • getRealm

      public String getRealm()
      Gets the realm name for the current authentication scope. null indicates "any realm" for the scope. Used for BASIC and DIGEST authentication.
      Returns:
      realm name for the scope
    • setRealm

      public void setRealm(String realm)
      Sets the realm name for the current authentication scope. Setting this to null (the default value) indicates "any realm" for the scope. Used for BASIC and DIGEST authentication.
      Parameters:
      realm - reaml name for the scope
    • getFormCharset

      public Charset getFormCharset()
      Gets the authentication form character set.
      Returns:
      authentication form character set
    • setFormCharset

      public void setFormCharset(Charset formCharset)
      Sets the authentication form character set for the form field values. Default is UTF-8.
      Parameters:
      formCharset - authentication form character set
    • getFormSelector

      public String getFormSelector()
      Gets the CSS selelector that identifies the form in a login page. When set, requires getUrl() to be pointing to a login page containing a login form.
      Returns:
      form selector
    • setFormSelector

      public void setFormSelector(String formSelector)
      Sets the CSS selelector that identifies the form in a login page. When set, requires getUrl() to be pointing to a login page containing a login form.
      Parameters:
      formSelector - form selector
    • setFormParam

      public void setFormParam(String name, String value)
      Sets an authentication form parameter (equivalent to "input" or other fields in HTML forms).
      Parameters:
      name - form parameter name
      value - form parameter value
    • setFormParams

      public void setFormParams(Map<String,String> params)
      Sets authentication form parameters (equivalent to "input" or other fields in HTML forms).
      Parameters:
      params - map of form parameter names and values
    • getFormParam

      public String getFormParam(String name)
      Gets an authentication form parameter (equivalent to "input" or other fields in HTML forms).
      Parameters:
      name - form parameter name
      Returns:
      form parameter value or null if no match is found
    • getFormParams

      public Map<String,String> getFormParams()
      Gets all authentication form parameters (equivalent to "input" or other fields in HTML forms).
      Returns:
      form parameters map (name and value)
    • getFormParamNames

      public List<String> getFormParamNames()
      Gets all authentication form parameter names. If no form parameters are set, it returns an empty array.
      Returns:
      HTTP request header names
    • removeFormParameter

      public String removeFormParameter(String name)
      Remove the authentication form parameter matching the given name.
      Parameters:
      name - name of form parameter to remove
      Returns:
      the previous value associated with the name, or null if there was no form parameter for the name.
    • isPreemptive

      public boolean isPreemptive()
      Gets whether to perform preemptive authentication (valid for "basic" authentication method).
      Returns:
      true to perform preemptive authentication
    • setPreemptive

      public void setPreemptive(boolean preemptive)
      Sets whether to perform preemptive authentication (valid for "basic" authentication method).
      Parameters:
      preemptive - true to perform preemptive authentication
    • getWorkstation

      public String getWorkstation()
      Gets the NTLM authentication workstation name.
      Returns:
      workstation name
    • setWorkstation

      public void setWorkstation(String workstation)
      Sets the NTLM authentication workstation name.
      Parameters:
      workstation - workstation name
    • getDomain

      public String getDomain()
      Gets the NTLM authentication domain.
      Returns:
      authentication domain
    • setDomain

      public void setDomain(String domain)
      Sets the NTLM authentication domain
      Parameters:
      domain - authentication domain
    • loadFromXML

      public void loadFromXML(XML xml)
      Specified by:
      loadFromXML in interface IXMLConfigurable
    • saveToXML

      public void saveToXML(XML xml)
      Specified by:
      saveToXML in interface IXMLConfigurable
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object