Class Authenticator
Applications use this class by overriding getPasswordAuthentication() in a sub-class. This method will
typically use the various getXXX() accessor methods to get information
about the entity requesting authentication. It must then acquire a
username and password either by interacting with the user or through
some other non-interactive means. The credentials are then returned
as a PasswordAuthentication return value.
An instance of this concrete sub-class is then registered
with the system by calling setDefault(Authenticator).
When authentication is required, the system will invoke one of the
requestPasswordAuthentication() methods which in turn will call the
getPasswordAuthentication() method of the registered object.
All methods that request authentication have a default implementation that fails.
- Since:
- 1.2
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumThe type of the entity requesting authentication.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic AuthenticatorGets the default authenticator.protected PasswordAuthenticationCalled when password authorization is needed.protected final StringGets thehostnameof the site or proxy requesting authentication, ornullif not available.protected final intGets the port number for the requested connection.protected final StringGets the prompt string given by the requestor.protected final StringGive the protocol that's requesting the connection.protected final StringGets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).protected final InetAddressGets theInetAddressof the site requesting authorization, ornullif not available.protected URLReturns the URL that resulted in this request for authentication.protected Authenticator.RequestorTypeReturns whether the requestor is a Proxy or a Server.static PasswordAuthenticationrequestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme) Ask the authenticator that has been registered with the system for a password.static PasswordAuthenticationrequestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) Ask the authenticator that has been registered with the system for a password.static PasswordAuthenticationrequestPasswordAuthentication(Authenticator authenticator, String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) Ask the givenauthenticatorfor a password.static PasswordAuthenticationrequestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme) Ask the authenticator that has been registered with the system for a password.requestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) Ask this authenticator for a password.static voidSets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.
- 
Constructor Details- 
Authenticatorpublic Authenticator()Constructor for subclasses to call.
 
- 
- 
Method Details- 
setDefaultSets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.- Parameters:
- a- The authenticator to be set. If a is- nullthen any previously set authenticator is removed.
 
- 
getDefaultGets the default authenticator.- Returns:
- The default authenticator, if set, nullotherwise.
- Since:
- 9
 
- 
requestPasswordAuthenticationpublic static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme) Ask the authenticator that has been registered with the system for a password.- Parameters:
- addr- The InetAddress of the site requesting authorization, or null if not known.
- port- the port for the requested connection
- protocol- The protocol that's requesting the connection (- getRequestingProtocol())
- prompt- A prompt string for the user
- scheme- The authentication scheme
- Returns:
- The username/password, or null if one can't be gotten.
 
- 
requestPasswordAuthenticationpublic static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme) Ask the authenticator that has been registered with the system for a password. This is the preferred method for requesting a password because the hostname can be provided in cases where the InetAddress is not available.- Parameters:
- host- The hostname of the site requesting authentication.
- addr- The InetAddress of the site requesting authentication, or null if not known.
- port- the port for the requested connection.
- protocol- The protocol that's requesting the connection (- getRequestingProtocol())
- prompt- A prompt string for the user which identifies the authentication realm.
- scheme- The authentication scheme
- Returns:
- The username/password, or null if one can't be gotten.
- Since:
- 1.4
 
- 
requestPasswordAuthenticationpublic static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) Ask the authenticator that has been registered with the system for a password.- Parameters:
- host- The hostname of the site requesting authentication.
- addr- The InetAddress of the site requesting authorization, or null if not known.
- port- the port for the requested connection
- protocol- The protocol that's requesting the connection (- getRequestingProtocol())
- prompt- A prompt string for the user
- scheme- The authentication scheme
- url- The requesting URL that caused the authentication
- reqType- The type (server or proxy) of the entity requesting authentication.
- Returns:
- The username/password, or null if one can't be gotten.
- Since:
- 1.5
 
- 
requestPasswordAuthenticationpublic static PasswordAuthentication requestPasswordAuthentication(Authenticator authenticator, String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) Ask the givenauthenticatorfor a password. If the givenauthenticatoris null, the authenticator, if any, that has been registered with the system usingsetDefaultis used.- Parameters:
- authenticator- the authenticator, or- null.
- host- The hostname of the site requesting authentication.
- addr- The InetAddress of the site requesting authorization, or null if not known.
- port- the port for the requested connection
- protocol- The protocol that's requesting the connection (- getRequestingProtocol())
- prompt- A prompt string for the user
- scheme- The authentication scheme
- url- The requesting URL that caused the authentication
- reqType- The type (server or proxy) of the entity requesting authentication.
- Returns:
- The username/password, or nullif one can't be gotten.
- Since:
- 9
 
- 
requestPasswordAuthenticationInstancepublic PasswordAuthentication requestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) Ask this authenticator for a password.- Parameters:
- host- The hostname of the site requesting authentication.
- addr- The InetAddress of the site requesting authorization, or null if not known.
- port- the port for the requested connection
- protocol- The protocol that's requesting the connection (- getRequestingProtocol())
- prompt- A prompt string for the user
- scheme- The authentication scheme
- url- The requesting URL that caused the authentication
- reqType- The type (server or proxy) of the entity requesting authentication.
- Returns:
- The username/password, or null if one can't be gotten
- Since:
- 9
 
- 
getRequestingHostGets thehostnameof the site or proxy requesting authentication, ornullif not available.- Returns:
- the hostname of the connection requiring authentication, or null if it's not available.
- Since:
- 1.4
 
- 
getRequestingSiteGets theInetAddressof the site requesting authorization, ornullif not available.- Returns:
- the InetAddress of the site requesting authorization, or null if it's not available.
 
- 
getRequestingPortprotected final int getRequestingPort()Gets the port number for the requested connection.- Returns:
- an intindicating the port for the requested connection.
 
- 
getRequestingProtocolGive the protocol that's requesting the connection. Often this will be based on a URL, but in a future JDK it could be, for example, "SOCKS" for a password-protected SOCKS5 firewall.- Returns:
- the protocol, optionally followed by "/version", where version is a version number.
- See Also:
 
- 
getRequestingPromptGets the prompt string given by the requestor.- Returns:
- the prompt string given by the requestor (realm for http requests)
 
- 
getRequestingSchemeGets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).- Returns:
- the scheme of the requestor
 
- 
getPasswordAuthenticationCalled when password authorization is needed. Subclasses should override the default implementation, which returns null.- Returns:
- The PasswordAuthentication collected from the user, or null if none is provided.
 
- 
getRequestingURLReturns the URL that resulted in this request for authentication. If the corresponding request does not specify a URL, this method returns null.- Returns:
- the requesting URL, or null if not available.
- Since:
- 1.5
 
- 
getRequestorTypeReturns whether the requestor is a Proxy or a Server.- Returns:
- the authentication type of the requestor
- Since:
- 1.5
 
 
-