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 StringMETHOD_BASICBASIC authentication method.static StringMETHOD_DIGESTDIGEST authentication method.static StringMETHOD_FORMForm-based authentication method.static StringMETHOD_KERBEROSExperimental: Kerberos authentication method.static StringMETHOD_NTLMNTLM authentication method.static StringMETHOD_SPNEGOExperimental: SPNEGO authentication method.
-
Constructor Summary
Constructors Constructor Description HttpAuthConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)CredentialsgetCredentials()StringgetDomain()Gets the NTLM authentication domain.CharsetgetFormCharset()Gets the authentication form character set.StringgetFormParam(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).StringgetFormPasswordField()Gets the name of the HTML field where the password is set.StringgetFormSelector()Gets the CSS selelector that identifies the form in a login page.StringgetFormUsernameField()Gets the name of the HTML field where the username is set.HostgetHost()Gets the host for the current authentication scope.StringgetMethod()Gets the authentication method.StringgetRealm()Gets the realm name for the current authentication scope.StringgetUrl()Gets the URL for "form" authentication.StringgetWorkstation()Gets the NTLM authentication workstation name.inthashCode()booleanisPreemptive()Gets whether to perform preemptive authentication (valid for "basic" authentication method).voidloadFromXML(XML xml)StringremoveFormParameter(String name)Remove the authentication form parameter matching the given name.voidsaveToXML(XML xml)voidsetCredentials(Credentials authCredentials)voidsetDomain(String domain)Sets 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.voidsetHost(Host host)Sets the host for the current authentication scope.voidsetMethod(String method)Sets the authentication method.voidsetPreemptive(boolean preemptive)Sets whether to perform preemptive authentication (valid for "basic" authentication method).voidsetRealm(String realm)Sets the realm name for the current authentication scope.voidsetUrl(String url)Sets the URL for "form" authentication.voidsetWorkstation(String workstation)Sets the NTLM authentication workstation name.StringtoString()
-
-
-
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.nullmeans 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.nullindicates "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
nullif 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
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
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:
loadFromXMLin interfaceIXMLConfigurable
-
saveToXML
public void saveToXML(XML xml)
- Specified by:
saveToXMLin interfaceIXMLConfigurable
-
-