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 protectedHttpBasicAuthentication(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 HttpBasicAuthenticationgetAuthentication(String challenge, Configuration conf)This method is responsible for providing Basic authentication information.static PatterngetBasicPattern()Provides a pattern which can be used by an outside resource to determine if this class can provide credentials based on simple header information.ConfigurationgetConf()List<String>getCredentials()Gets the Basic credentials generated by this HttpBasicAuthentication objectStringgetRealm()Gets the realm attribute of the HttpBasicAuthentication object.voidsetConf(Configuration conf)
-
-
-
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 formWWW-Authenticate: Basic realm="myrealm"- Parameters:
challenge- WWW-Authenticate header from web serverconf- a populatedConfiguration- Throws:
HttpAuthenticationException- if the authentication fails or if the password or username is null
-
-
Method Detail
-
setConf
public void setConf(Configuration conf)
- Specified by:
setConfin interfaceConfigurable
-
getConf
public Configuration getConf()
- Specified by:
getConfin interfaceConfigurable
-
getCredentials
public List<String> getCredentials()
Gets the Basic credentials generated by this HttpBasicAuthentication object- Specified by:
getCredentialsin interfaceHttpAuthentication- 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 thegetAuthentication(String, Configuration)static method- Specified by:
getRealmin interfaceHttpAuthentication- 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 populatedConfiguration- 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.
-
-