Package org.htmlunit
Class DefaultCredentialsProvider
java.lang.Object
org.htmlunit.DefaultCredentialsProvider
- All Implemented Interfaces:
Serializable,org.apache.http.client.CredentialsProvider
public class DefaultCredentialsProvider
extends Object
implements org.apache.http.client.CredentialsProvider, Serializable
Default HtmlUnit implementation of the
CredentialsProvider interface. Provides
credentials for both web servers and proxies. Supports Digest
authentication, Socks authentication and Basic HTTP authentication.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classWe have to wrapAuthScopeinstances in a serializable proxy so that theDefaultCredentialsProviderclass can be serialized correctly.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThenullvalue represents any host.static final intThe-1value represents any port.static final StringThenullvalue represents any realm.static final StringThenullvalue represents any authentication scheme.private final Map<DefaultCredentialsProvider.AuthScopeProxy, org.apache.http.auth.Credentials> private static DefaultCredentialsProvider.SocksProxyAuthenticator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCredentials(String username, char[] password) Adds credentials for the specified username/password for any host/port/realm combination.voidaddCredentials(String username, char[] password, String host, int port, String realm) Adds credentials for the specified username/password on the specified host/port for the specified realm.voidaddCredentials(String username, String password) Deprecated.as of version 3.4.0; use addCredentials(String, char[]) insteadvoidaddCredentials(String username, String password, String host, int port, String realm) Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addCredentials(String, char[], String, int, String) insteadvoidaddNTLMCredentials(String username, char[] password, String host, int port, String workstation, String domain) Adds NTLM credentials for the specified username/password on the specified host/port.voidaddNTLMCredentials(String username, String password, String host, int port, String workstation, String domain) Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addNTLMCredentials(String, char[], String, int, String, String) insteadvoidaddSocksCredentials(String username, char[] password, String host, int port) Adds Socks credentials for the specified username/password on the specified host/port.voidaddSocksCredentials(String username, String password, String host, int port) Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addSocksCredentials(String, char[], String, int) insteadvoidclear()org.apache.http.auth.CredentialsgetCredentials(org.apache.http.auth.AuthScope authscope) private static voidinitSocksAuthenticatorIfNeeded(org.apache.http.client.CredentialsProvider provider) private static org.apache.http.auth.CredentialsmatchCredentials(Map<DefaultCredentialsProvider.AuthScopeProxy, org.apache.http.auth.Credentials> map, org.apache.http.auth.AuthScope authscope) Find matchingcredentialsfor the given authentication scope.booleanremoveCredentials(org.apache.http.auth.AuthScope authscope) Removes the credentials from the AuthScope.voidsetCredentials(org.apache.http.auth.AuthScope authscope, org.apache.http.auth.Credentials credentials) toString()
-
Field Details
-
ANY_HOST
Thenullvalue represents any host. -
ANY_PORT
public static final int ANY_PORTThe-1value represents any port.- See Also:
-
ANY_REALM
Thenullvalue represents any realm. -
ANY_SCHEME
Thenullvalue represents any authentication scheme. -
SocksAuthenticator_
-
credentialsMap_
private final Map<DefaultCredentialsProvider.AuthScopeProxy,org.apache.http.auth.Credentials> credentialsMap_
-
-
Constructor Details
-
DefaultCredentialsProvider
public DefaultCredentialsProvider()
-
-
Method Details
-
addCredentials
Deprecated.as of version 3.4.0; use addCredentials(String, char[]) insteadAdds 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 may receive the specified username and password.- Parameters:
username- the username for the new credentialspassword- the password for the new credentials
-
addCredentials
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 may receive the specified username and password.- Parameters:
username- the username for the new credentialspassword- the password for the new credentials
-
addCredentials
@Deprecated public void addCredentials(String username, String password, String host, int port, String realm) Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addCredentials(String, char[], String, int, String) insteadAdds 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 credentialspassword- the password for the new credentialshost- the host to which to the new credentials apply (nullif 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 (nullif applicable to any realm)
-
addCredentials
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 credentialspassword- the password for the new credentialshost- the host to which to the new credentials apply (nullif 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 (nullif applicable to any realm)
-
addNTLMCredentials
@Deprecated public void addNTLMCredentials(String username, String password, String host, int port, String workstation, String domain) Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addNTLMCredentials(String, char[], String, int, String, String) insteadAdds 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 notpassword- the password for the new credentialshost- the host to which to the new credentials apply (nullif applicable to any host)port- the port to which to the new credentials apply (negative if applicable to any port)workstation- The workstation the authentication request is originating from. Essentially, the computer name for this machine.domain- the domain to authenticate within
-
addNTLMCredentials
public void addNTLMCredentials(String username, char[] password, String host, int port, String workstation, String domain) 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 notpassword- the password for the new credentialshost- the host to which to the new credentials apply (nullif applicable to any host)port- the port to which to the new credentials apply (negative if applicable to any port)workstation- The workstation the authentication request is originating from. Essentially, the computer name for this machine.domain- the domain to authenticate within
-
addSocksCredentials
@Deprecated public void addSocksCredentials(String username, String password, String host, int port) Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addSocksCredentials(String, char[], String, int) insteadAdds Socks credentials for the specified username/password on the specified host/port.- Parameters:
username- the username for the new credentialspassword- the password for the new credentialshost- the host to which to the new credentials apply (nullif applicable to any host)port- the port to which to the new credentials apply (negative if applicable to any port)
-
addSocksCredentials
Adds Socks credentials for the specified username/password on the specified host/port.- Parameters:
username- the username for the new credentialspassword- the password for the new credentialshost- the host to which to the new credentials apply (nullif applicable to any host)port- the port to which to the new credentials apply (negative if applicable to any port)
-
initSocksAuthenticatorIfNeeded
private static void initSocksAuthenticatorIfNeeded(org.apache.http.client.CredentialsProvider provider) -
setCredentials
public void setCredentials(org.apache.http.auth.AuthScope authscope, org.apache.http.auth.Credentials credentials) - Specified by:
setCredentialsin interfaceorg.apache.http.client.CredentialsProvider
-
matchCredentials
private static org.apache.http.auth.Credentials matchCredentials(Map<DefaultCredentialsProvider.AuthScopeProxy, org.apache.http.auth.Credentials> map, org.apache.http.auth.AuthScope authscope) Find matchingcredentialsfor the given authentication scope.- Parameters:
map- the credentials hash mapauthscope- theauthentication scope- Returns:
- the credentials
-
getCredentials
public org.apache.http.auth.Credentials getCredentials(org.apache.http.auth.AuthScope authscope) - Specified by:
getCredentialsin interfaceorg.apache.http.client.CredentialsProvider
-
removeCredentials
public boolean removeCredentials(org.apache.http.auth.AuthScope authscope) Removes the credentials from the AuthScope.- Parameters:
authscope- the AuthScope to remove the credentials of- Returns:
- whether it was removed or not
-
toString
-
clear
public void clear()- Specified by:
clearin interfaceorg.apache.http.client.CredentialsProvider
-