Package org.htmlunit
Class DefaultCredentialsProvider
- java.lang.Object
-
- org.htmlunit.DefaultCredentialsProvider
-
- All Implemented Interfaces:
java.io.Serializable
,org.apache.http.client.CredentialsProvider
public class DefaultCredentialsProvider extends java.lang.Object implements org.apache.http.client.CredentialsProvider, java.io.Serializable
Default HtmlUnit implementation of theCredentialsProvider
interface. Provides credentials for both web servers and proxies. Supports Digest authentication, Socks authentication and Basic HTTP authentication.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DefaultCredentialsProvider.AuthScopeProxy
We have to wrapAuthScope
instances in a serializable proxy so that theDefaultCredentialsProvider
class can be serialized correctly.private static class
DefaultCredentialsProvider.SocksProxyAuthenticator
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANY_HOST
Thenull
value represents any host.static int
ANY_PORT
The-1
value represents any port.static java.lang.String
ANY_REALM
Thenull
value represents any realm.static java.lang.String
ANY_SCHEME
Thenull
value represents any authentication scheme.private java.util.Map<DefaultCredentialsProvider.AuthScopeProxy,org.apache.http.auth.Credentials>
credentialsMap_
private static DefaultCredentialsProvider.SocksProxyAuthenticator
SocksAuthenticator_
-
Constructor Summary
Constructors Constructor Description DefaultCredentialsProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCredentials(java.lang.String username, char[] password)
Adds credentials for the specified username/password for any host/port/realm combination.void
addCredentials(java.lang.String username, char[] 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
addCredentials(java.lang.String username, java.lang.String password)
Deprecated.as of version 3.4.0; use addCredentials(String, char[]) insteadvoid
addCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.String realm)
Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addCredentials(String, char[], String, int, String) insteadvoid
addNTLMCredentials(java.lang.String username, char[] password, java.lang.String host, int port, java.lang.String workstation, java.lang.String domain)
Adds NTLM credentials for the specified username/password on the specified host/port.void
addNTLMCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.String workstation, java.lang.String domain)
Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addNTLMCredentials(String, char[], String, int, String, String) insteadvoid
addSocksCredentials(java.lang.String username, char[] password, java.lang.String host, int port)
Adds Socks credentials for the specified username/password on the specified host/port.void
addSocksCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port)
Deprecated.as of version 3.4.0; use DefaultCredentialsProvider.addSocksCredentials(String, char[], String, int) insteadvoid
clear()
org.apache.http.auth.Credentials
getCredentials(org.apache.http.auth.AuthScope authscope)
private static void
initSocksAuthenticatorIfNeeded(org.apache.http.client.CredentialsProvider provider)
private static org.apache.http.auth.Credentials
matchCredentials(java.util.Map<DefaultCredentialsProvider.AuthScopeProxy,org.apache.http.auth.Credentials> map, org.apache.http.auth.AuthScope authscope)
Find matchingcredentials
for the given authentication scope.boolean
removeCredentials(org.apache.http.auth.AuthScope authscope)
Removes the credentials from the AuthScope.void
setCredentials(org.apache.http.auth.AuthScope authscope, org.apache.http.auth.Credentials credentials)
java.lang.String
toString()
-
-
-
Field Detail
-
ANY_HOST
public static final java.lang.String ANY_HOST
Thenull
value represents any host.
-
ANY_PORT
public static final int ANY_PORT
The-1
value represents any port.- See Also:
- Constant Field Values
-
ANY_REALM
public static final java.lang.String ANY_REALM
Thenull
value represents any realm.
-
ANY_SCHEME
public static final java.lang.String ANY_SCHEME
Thenull
value represents any authentication scheme.
-
SocksAuthenticator_
private static DefaultCredentialsProvider.SocksProxyAuthenticator SocksAuthenticator_
-
credentialsMap_
private final java.util.Map<DefaultCredentialsProvider.AuthScopeProxy,org.apache.http.auth.Credentials> credentialsMap_
-
-
Method Detail
-
addCredentials
@Deprecated public void addCredentials(java.lang.String username, java.lang.String password)
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
public void addCredentials(java.lang.String username, char[] 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 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(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.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 (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)
-
addCredentials
public void addCredentials(java.lang.String username, char[] 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 credentialspassword
- the password for the new credentialshost
- 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)
-
addNTLMCredentials
@Deprecated public void addNTLMCredentials(java.lang.String username, java.lang.String password, java.lang.String host, int port, java.lang.String workstation, java.lang.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 (null
if 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(java.lang.String username, char[] password, java.lang.String host, int port, java.lang.String workstation, java.lang.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 (null
if 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(java.lang.String username, java.lang.String password, java.lang.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 (null
if applicable to any host)port
- the port to which to the new credentials apply (negative if applicable to any port)
-
addSocksCredentials
public void addSocksCredentials(java.lang.String username, char[] password, java.lang.String host, int port)
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 (null
if 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:
setCredentials
in interfaceorg.apache.http.client.CredentialsProvider
-
matchCredentials
private static org.apache.http.auth.Credentials matchCredentials(java.util.Map<DefaultCredentialsProvider.AuthScopeProxy,org.apache.http.auth.Credentials> map, org.apache.http.auth.AuthScope authscope)
Find matchingcredentials
for 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:
getCredentials
in 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clear
public void clear()
- Specified by:
clear
in interfaceorg.apache.http.client.CredentialsProvider
-
-