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 Summary
Fields Modifier and Type Field Description static String
METHOD_BASIC
BASIC authentication method.static String
METHOD_DIGEST
DIGEST authentication method.static String
METHOD_FORM
Form-based authentication method.static String
METHOD_KERBEROS
Experimental: Kerberos authentication method.static String
METHOD_NTLM
NTLM authentication method.static String
METHOD_SPNEGO
Experimental: SPNEGO authentication method.
-
Constructor Summary
Constructors Constructor Description HttpAuthConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Credentials
getCredentials()
String
getDomain()
Gets the NTLM authentication domain.Charset
getFormCharset()
Gets the authentication form character set.String
getFormParam(String name)
Gets an authentication form parameter (equivalent to "input" or other fields in HTML forms).List<String>
getFormParamNames()
Gets all authentication form parameter names.Map<String,String>
getFormParams()
Gets all authentication form parameters (equivalent to "input" or other fields in HTML forms).String
getFormPasswordField()
Gets the name of the HTML field where the password is set.String
getFormSelector()
Gets the CSS selelector that identifies the form in a login page.String
getFormUsernameField()
Gets the name of the HTML field where the username is set.Host
getHost()
Gets the host for the current authentication scope.String
getMethod()
Gets the authentication method.String
getRealm()
Gets the realm name for the current authentication scope.String
getUrl()
Gets the URL for "form" authentication.String
getWorkstation()
Gets the NTLM authentication workstation name.int
hashCode()
boolean
isPreemptive()
Gets whether to perform preemptive authentication (valid for "basic" authentication method).void
loadFromXML(XML xml)
String
removeFormParameter(String name)
Remove the authentication form parameter matching the given name.void
saveToXML(XML xml)
void
setCredentials(Credentials authCredentials)
void
setDomain(String domain)
Sets the NTLM authentication domainvoid
setFormCharset(Charset formCharset)
Sets the authentication form character set for the form field values.void
setFormParam(String name, String value)
Sets an authentication form parameter (equivalent to "input" or other fields in HTML forms).void
setFormParams(Map<String,String> params)
Sets authentication form parameters (equivalent to "input" or other fields in HTML forms).void
setFormPasswordField(String formPasswordField)
Sets the name of the HTML field where the password is set.void
setFormSelector(String formSelector)
Sets the CSS selelector that identifies the form in a login page.void
setFormUsernameField(String formUsernameField)
Sets the name of the HTML field where the username is set.void
setHost(Host host)
Sets the host for the current authentication scope.void
setMethod(String method)
Sets the authentication method.void
setPreemptive(boolean preemptive)
Sets whether to perform preemptive authentication (valid for "basic" authentication method).void
setRealm(String realm)
Sets the realm name for the current authentication scope.void
setUrl(String url)
Sets the URL for "form" authentication.void
setWorkstation(String workstation)
Sets the NTLM authentication workstation name.String
toString()
-
-
-
Field Detail
-
METHOD_FORM
public static final String METHOD_FORM
Form-based authentication method.- See Also:
- Constant Field Values
-
METHOD_BASIC
public static final String METHOD_BASIC
BASIC authentication method.- See Also:
- Constant Field Values
-
METHOD_DIGEST
public static final String METHOD_DIGEST
DIGEST authentication method.- See Also:
- Constant Field Values
-
METHOD_NTLM
public static final String METHOD_NTLM
NTLM authentication method.- See Also:
- Constant Field Values
-
METHOD_SPNEGO
public static final String METHOD_SPNEGO
Experimental: SPNEGO authentication method.- See Also:
- Constant Field Values
-
METHOD_KERBEROS
public static final String METHOD_KERBEROS
Experimental: Kerberos authentication method.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
- 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, requiresgetUrl()
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, requiresgetUrl()
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 namevalue
- 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 interfaceIXMLConfigurable
-
saveToXML
public void saveToXML(XML xml)
- Specified by:
saveToXML
in interfaceIXMLConfigurable
-
-