Class HttpAuthConfig
java.lang.Object
com.norconex.collector.http.fetch.impl.HttpAuthConfig
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBASIC authentication method.static final StringDIGEST authentication method.static final StringForm-based authentication method.static final StringExperimental: Kerberos authentication method.static final StringNTLM authentication method.static final StringExperimental: SPNEGO authentication method. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the NTLM authentication domain.Gets the authentication form character set.getFormParam(String name) Gets an authentication form parameter (equivalent to "input" or other fields in HTML forms).Gets all authentication form parameter names.Gets all authentication form parameters (equivalent to "input" or other fields in HTML forms).Gets the name of the HTML field where the password is set.Gets the CSS selelector that identifies the form in a login page.Gets the name of the HTML field where the username is set.getHost()Gets the host for the current authentication scope.Gets the authentication method.getRealm()Gets the realm name for the current authentication scope.getUrl()Gets the URL for "form" authentication.Gets the NTLM authentication workstation name.inthashCode()booleanGets whether to perform preemptive authentication (valid for "basic" authentication method).voidloadFromXML(XML xml) removeFormParameter(String name) Remove the authentication form parameter matching the given name.voidvoidsetCredentials(Credentials authCredentials) voidSets the NTLM authentication domainvoidsetFormCharset(Charset formCharset) Sets the authentication form character set for the form field values.voidsetFormParam(String name, String value) Sets an authentication form parameter (equivalent to "input" or other fields in HTML forms).voidsetFormParams(Map<String, String> params) Sets authentication form parameters (equivalent to "input" or other fields in HTML forms).voidsetFormPasswordField(String formPasswordField) Sets the name of the HTML field where the password is set.voidsetFormSelector(String formSelector) Sets the CSS selelector that identifies the form in a login page.voidsetFormUsernameField(String formUsernameField) Sets the name of the HTML field where the username is set.voidSets the host for the current authentication scope.voidSets the authentication method.voidsetPreemptive(boolean preemptive) Sets whether to perform preemptive authentication (valid for "basic" authentication method).voidSets the realm name for the current authentication scope.voidSets the URL for "form" authentication.voidsetWorkstation(String workstation) Sets the NTLM authentication workstation name.toString()
-
Field Details
-
METHOD_FORM
Form-based authentication method.- See Also:
-
METHOD_BASIC
BASIC authentication method.- See Also:
-
METHOD_DIGEST
DIGEST authentication method.- See Also:
-
METHOD_NTLM
NTLM authentication method.- See Also:
-
METHOD_SPNEGO
Experimental: SPNEGO authentication method.- See Also:
-
METHOD_KERBEROS
Experimental: Kerberos authentication method.- See Also:
-
-
Constructor Details
-
HttpAuthConfig
public HttpAuthConfig()
-
-
Method Details
-
getMethod
Gets the authentication method.- Returns:
- authentication method
-
setMethod
Sets the authentication method.
Valid values are (case insensitive):- form
- basic
- digest
- ntlm
- spnego
- kerberos
- Parameters:
method- authentication method
-
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
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
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
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
-
setCredentials
-
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
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
Gets the host for the current authentication scope.nullmeans any host names for the scope. Used for BASIC and DIGEST authentication.- Returns:
- host for the scope
-
setHost
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
Gets the realm name for the current authentication scope.nullindicates "any realm" for the scope. Used for BASIC and DIGEST authentication.- Returns:
- realm name for the scope
-
setRealm
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
Gets the authentication form character set.- Returns:
- authentication form character set
-
setFormCharset
Sets the authentication form character set for the form field values. Default is UTF-8.- Parameters:
formCharset- authentication form character set
-
getFormSelector
Gets the CSS selelector that identifies the form in a login page. When set, requiresgetUrl()to be pointing to a login page containing a login form.- Returns:
- form selector
-
setFormSelector
Sets the CSS selelector that identifies the form in a login page. When set, requiresgetUrl()to be pointing to a login page containing a login form.- Parameters:
formSelector- form selector
-
setFormParam
Sets an authentication form parameter (equivalent to "input" or other fields in HTML forms).- Parameters:
name- form parameter namevalue- form parameter value
-
setFormParams
Sets authentication form parameters (equivalent to "input" or other fields in HTML forms).- Parameters:
params- map of form parameter names and values
-
getFormParam
Gets an authentication form parameter (equivalent to "input" or other fields in HTML forms).- Parameters:
name- form parameter name- Returns:
- form parameter value or
nullif no match is found
-
getFormParams
Gets all authentication form parameters (equivalent to "input" or other fields in HTML forms).- Returns:
- form parameters map (name and value)
-
getFormParamNames
Gets all authentication form parameter names. If no form parameters are set, it returns an empty array.- Returns:
- HTTP request header names
-
removeFormParameter
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
nullif there was no form parameter for the name.
-
isPreemptive
public boolean isPreemptive()Gets whether to perform preemptive authentication (valid for "basic" authentication method).- Returns:
trueto perform preemptive authentication
-
setPreemptive
public void setPreemptive(boolean preemptive) Sets whether to perform preemptive authentication (valid for "basic" authentication method).- Parameters:
preemptive-trueto perform preemptive authentication
-
getWorkstation
Gets the NTLM authentication workstation name.- Returns:
- workstation name
-
setWorkstation
Sets the NTLM authentication workstation name.- Parameters:
workstation- workstation name
-
getDomain
Gets the NTLM authentication domain.- Returns:
- authentication domain
-
setDomain
Sets the NTLM authentication domain- Parameters:
domain- authentication domain
-
loadFromXML
- Specified by:
loadFromXMLin interfaceIXMLConfigurable
-
saveToXML
- Specified by:
saveToXMLin interfaceIXMLConfigurable
-
equals
-
hashCode
public int hashCode() -
toString
-