## com.gargoylesoftware.htmlunit
Class DefaultCredentialsProvider

    java.lang.Object
      com.gargoylesoftware.htmlunit.DefaultCredentialsProvider

All Implemented Interfaces:
  java.io.Serializable, org.apache.commons.httpclient.auth.CredentialsProvider

    public class DefaultCredentialsProvider

extends java.lang.Object
implements org.apache.commons.httpclient.auth.CredentialsProvider, java.io.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: 4789 $
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(java.lang.String username, java.lang.String password)` Adds credentials for the specified username/password for any host/port/realm combination.
`void` `addCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.String realm)` Adds credentials for the specified username/password on the specified host/port for the specified realm.
`void` `addNTLMCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.String clientHost, java.lang.String clientDomain)` Adds NTLM credentials for the specified username/password on the specified host/port.
`void` `addNTLMProxyCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.String clientHost, java.lang.String clientDomain)` Adds NTLM proxy credentials for the specified username/password on the specified host/port.
`void` `addProxyCredentials(java.lang.String username, java.lang.String password)` Adds proxy credentials for the specified username/password for any host/port/realm combination.
`void` `addProxyCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port)` Adds proxy credentials for the specified username/password on the specified host/port.
`protected boolean` `alreadyAnswered(org.apache.commons.httpclient.auth.AuthScheme scheme, java.lang.String host, int port, boolean proxy)` Returns `true` if this provider has already provided an answer for the specified (scheme, host, port, proxy) combination.
`protected java.lang.Object` `buildKey(org.apache.commons.httpclient.auth.AuthScheme scheme, java.lang.String host, int port, boolean proxy)` Builds a key with the specified data.
`protected void` `clearAnswered()` Clears the cache of answered (scheme, host, port, proxy) combinations.
`org.apache.commons.httpclient.Credentials` `getCredentials(org.apache.commons.httpclient.auth.AuthScheme scheme, java.lang.String host, int port, boolean proxy)` Returns the credentials associated with the specified scheme, host and port.
`protected void` `markAsAnswered(org.apache.commons.httpclient.auth.AuthScheme scheme, java.lang.String host, int port, boolean proxy)` Marks the specified (scheme, host, port, proxy) combination as having already been processed.
`protected boolean` `matchHost(org.apache.commons.httpclient.auth.AuthScope scope, java.lang.String host)`
`protected boolean` `matchPort(org.apache.commons.httpclient.auth.AuthScope scope, int port)`
`protected boolean` `matchRealm(org.apache.commons.httpclient.auth.AuthScope scope, org.apache.commons.httpclient.auth.AuthScheme scheme)`
`protected boolean` `matchScheme(org.apache.commons.httpclient.auth.AuthScope scope, org.apache.commons.httpclient.auth.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(java.lang.String username,
                               java.lang.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(java.lang.String username,
                               java.lang.String password,
                               java.lang.String host,
                               int port,
                               java.lang.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(java.lang.String username,
                                    java.lang.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(java.lang.String username,
                                    java.lang.String password,
                                    java.lang.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(java.lang.String username,
                                   java.lang.String password,
                                   java.lang.String host,
                                   int port,
                                   java.lang.String clientHost,
                                   java.lang.String clientDomain)

  Adds NTLM credentials for the specified username/password on the specified host/port.

  Parameters:
    `username` - the username for the new credentials; 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(java.lang.String username,
                                        java.lang.String password,
                                        java.lang.String host,
                                        int port,
                                        java.lang.String clientHost,
                                        java.lang.String clientDomain)

  Adds NTLM proxy credentials for the specified username/password on the specified host/port.

  Parameters:
    `username` - the username for the new credentials; 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 org.apache.commons.httpclient.Credentials getCredentials(org.apache.commons.httpclient.auth.AuthScheme scheme,
                                                                    java.lang.String host,
                                                                    int port,
                                                                    boolean proxy)
                                                             throws org.apache.commons.httpclient.auth.CredentialsNotAvailableException

  Returns the credentials associated with the specified scheme, host and port.

  Specified by:
    `getCredentials` in interface `org.apache.commons.httpclient.auth.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:
    `org.apache.commons.httpclient.auth.CredentialsNotAvailableException` - if the specified credentials cannot be provided due to an error
  See Also:
    `CredentialsProvider.getCredentials(AuthScheme, String, int, boolean)`

### matchRealm

    protected boolean matchRealm(org.apache.commons.httpclient.auth.AuthScope scope,
                                 org.apache.commons.httpclient.auth.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(org.apache.commons.httpclient.auth.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(org.apache.commons.httpclient.auth.AuthScope scope,
                                java.lang.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(org.apache.commons.httpclient.auth.AuthScope scope,
                                  org.apache.commons.httpclient.auth.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(org.apache.commons.httpclient.auth.AuthScheme scheme,
                                      java.lang.String host,
                                      int port,
                                      boolean proxy)

  Returns `true` if this provider has already provided an answer for the specified (scheme, host, port, proxy) combination.

  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(org.apache.commons.httpclient.auth.AuthScheme scheme,
                                  java.lang.String host,
                                  int port,
                                  boolean proxy)

  Marks the specified (scheme, host, port, proxy) combination as having already been processed.

  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 java.lang.Object buildKey(org.apache.commons.httpclient.auth.AuthScheme scheme,
                                        java.lang.String host,
                                        int port,
                                        boolean proxy)

  Builds 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

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