com.gargoylesoftware.htmlunit
Class DefaultCredentialsProvider

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.DefaultCredentialsProvider
All Implemented Interfaces:
Serializable, CredentialsProvider

public class DefaultCredentialsProvider
extends Object
implements CredentialsProvider, Serializable

Default HtmlUnit implementation of the CredentialsProvider interface. Provides credentials for both web servers and proxies. Supports NTLM authentication, Digest authentication, and Basic HTTP authentication.

Version:
$Revision: 2132 $
Author:
Daniel Gredler, Vikram Shitole, Marc Guillemot, Ahmed Ashour
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.commons.httpclient.auth.CredentialsProvider
PROVIDER
 
Constructor Summary
DefaultCredentialsProvider()
          Creates a new DefaultCredentialsProvider instance.
 
Method Summary
 void addCredentials(String username, String password)
          Adds credentials for the specified username/password for any host/port/realm combination.
 void addCredentials(String username, String password, String host, int port, String realm)
          Adds credentials for the specified username/password on the specified host/port for the specified realm.
 void addNTLMCredentials(String username, String password, String host, int port, String clientHost, String clientDomain)
          Adds NTLM credentials for the specified username/password on the specified host/port.
 void addNTLMProxyCredentials(String username, String password, String host, int port, String clientHost, String clientDomain)
          Adds NTLM proxy credentials for the specified username/password on the specified host/port.
 void addProxyCredentials(String username, String password)
          Adds proxy credentials for the specified username/password for any host/port/realm combination.
 void addProxyCredentials(String username, String password, String host, int port)
          Adds proxy credentials for the specified username/password on the specified host/port.
protected  boolean alreadyAnswered(AuthScheme scheme, String host, int port, boolean proxy)
          Indicates if this provider has already provided an answer for this (scheme, host, port, proxy).
protected  Object buildKey(AuthScheme scheme, String host, int port, boolean proxy)
          Build a key with the specified data
protected  void clearAnswered()
          Clears the cache of answered (scheme, host, port, proxy) combinations.
 Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy)
          Returns the credentials associated with the specified scheme, host and port
protected  Log getLog()
          Return the log object for this class
protected  void markAsAnswered(AuthScheme scheme, String host, int port, boolean proxy)
           
protected  boolean matchHost(AuthScope scope, String host)
           
protected  boolean matchPort(AuthScope scope, int port)
           
protected  boolean matchRealm(AuthScope scope, AuthScheme scheme)
           
protected  boolean matchScheme(AuthScope scope, AuthScheme scheme)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCredentialsProvider

public DefaultCredentialsProvider()
Creates a new DefaultCredentialsProvider instance.

Method Detail

addCredentials

public void addCredentials(String username,
                           String password)
Adds credentials for the specified username/password for any host/port/realm combination. The credentials may be for any authentication scheme, including NTLM, digest and basic HTTP authentication. If you are using sensitive username/password information, please do NOT use this method. If you add credentials using this method, any server that requires authentication will receive the specified username and password.

Parameters:
username - The username for the new credentials.
password - The password for the new credentials.

addCredentials

public void addCredentials(String username,
                           String password,
                           String host,
                           int port,
                           String realm)
Adds credentials for the specified username/password on the specified host/port for the specified realm. The credentials may be for any authentication scheme, including NTLM, digest and basic HTTP authentication.

Parameters:
username - The username for the new credentials.
password - The password for the new credentials.
host - The host to which to the new credentials apply (null if applicable to any host).
port - The port to which to the new credentials apply (negative if applicable to any port).
realm - The realm to which to the new credentials apply (null if applicable to any realm).

addProxyCredentials

public void addProxyCredentials(String username,
                                String password)
Adds proxy credentials for the specified username/password for any host/port/realm combination.

Parameters:
username - The username for the new credentials.
password - The password for the new credentials.

addProxyCredentials

public void addProxyCredentials(String username,
                                String password,
                                String host,
                                int port)
Adds proxy credentials for the specified username/password on the specified host/port.

Parameters:
username - The username for the new credentials.
password - The password for the new credentials.
host - The host to which to the new credentials apply (null if applicable to any host).
port - The port to which to the new credentials apply (negative if applicable to any port).

addNTLMCredentials

public void addNTLMCredentials(String username,
                               String password,
                               String host,
                               int port,
                               String clientHost,
                               String clientDomain)
Adds NTLM credentials for the specified username/password on the specified host/port.

Parameters:
username - The username for the new credentials. This should not include the domain to authenticate with. For example: "user" is correct whereas "DOMAIN\\user" is not.
password - The password for the new credentials.
host - The host to which to the new credentials apply (null if applicable to any host).
port - The port to which to the new credentials apply (negative if applicable to any port).
clientHost - The host the authentication request is originating from. Essentially, the computer name for this machine.
clientDomain - The domain to authenticate within.

addNTLMProxyCredentials

public void addNTLMProxyCredentials(String username,
                                    String password,
                                    String host,
                                    int port,
                                    String clientHost,
                                    String clientDomain)
Adds NTLM proxy credentials for the specified username/password on the specified host/port.

Parameters:
username - The username for the new credentials. This should not include the domain to authenticate with. For example: "user" is correct whereas "DOMAIN\\user" is not.
password - The password for the new credentials.
host - The host to which to the new credentials apply (null if applicable to any host).
port - The port to which to the new credentials apply (negative if applicable to any port).
clientHost - The host the authentication request is originating from. Essentially, the computer name for this machine.
clientDomain - The domain to authenticate within.

getCredentials

public Credentials getCredentials(AuthScheme scheme,
                                  String host,
                                  int port,
                                  boolean proxy)
                           throws CredentialsNotAvailableException
Returns the credentials associated with the specified scheme, host and port

Specified by:
getCredentials in interface CredentialsProvider
Parameters:
scheme - The authentication scheme being used (basic, digest, NTLM, etc).
host - The host we are authenticating for.
port - The port we are authenticating for.
proxy - Whether or not we are authenticating using a proxy.
Returns:
The credentials corresponding to the specified scheme, host and port or null if already asked for it to avoid infinite loop
Throws:
CredentialsNotAvailableException - If the specified credentials cannot be provided due to an error.
See Also:
CredentialsProvider.getCredentials(AuthScheme, String, int, boolean)

matchRealm

protected boolean matchRealm(AuthScope scope,
                             AuthScheme scheme)
Parameters:
scheme - the request scheme for which Credentials are asked
scope - the configured authorization scope
Returns:
true if the scope's realm matches the one of the scheme

matchPort

protected boolean matchPort(AuthScope scope,
                            int port)
Parameters:
port - the request port for which Credentials are asked
scope - the configured authorization scope
Returns:
true if the scope's port matches the provided one

matchHost

protected boolean matchHost(AuthScope scope,
                            String host)
Parameters:
host - the request host for which Credentials are asked
scope - the configured authorization scope
Returns:
true if the scope's host matches the provided one

matchScheme

protected boolean matchScheme(AuthScope scope,
                              AuthScheme scheme)
Parameters:
scheme - the request scheme for which Credentials are asked
scope - the configured authorization scope
Returns:
true if the scope's scheme matches the provided one

alreadyAnswered

protected boolean alreadyAnswered(AuthScheme scheme,
                                  String host,
                                  int port,
                                  boolean proxy)
Indicates if this provider has already provided an answer for this (scheme, host, port, proxy).

Parameters:
scheme - The scheme
host - the server name.
port - the server port.
proxy - is proxy
Returns:
true if the provider has already provided an answer for this.

markAsAnswered

protected void markAsAnswered(AuthScheme scheme,
                              String host,
                              int port,
                              boolean proxy)
Parameters:
scheme - The scheme
host - the server name.
port - the server port.
proxy - is proxy

clearAnswered

protected void clearAnswered()
Clears the cache of answered (scheme, host, port, proxy) combinations.


buildKey

protected Object buildKey(AuthScheme scheme,
                          String host,
                          int port,
                          boolean proxy)
Build a key with the specified data

Parameters:
scheme - The scheme
host - the server name.
port - the server port.
proxy - is proxy
Returns:
the new key.

getLog

protected final Log getLog()
Return the log object for this class

Returns:
The log object


Copyright © 2002-2010 Gargoyle Software Inc.. All Rights Reserved.