This
abstract class defines a customizable mechanism for requesting and
performing
password authentication
when required in URL-based networking. The static
setDefault( )
method establishes the systemwide Authenticator.
An Authenticator implementation can obtain the
required authentication information from the user however it wants
(e.g., through a text- or a GUI-based interface).
setDefault( ) can be called only once; subsequent
calls are ignored. Calling setDefault( ) requires
an appropriate NetPermission.
When an application or the Java runtime system
requires password authentication (to read the contents of a specified
URL, for example), it calls the static
requestPasswordAuthentication( ) method, passing
arguments that specify the host and port for which the password is
required and a prompt that may be displayed to the user. This method
looks up the default Authenticator for the system
and calls its getPasswordAuthentication( ) method.
Calling requestPasswordAuthentication( ) requires
an appropriate NetPermission.
Authenticator is an
abstract class; its default implementation of
getPasswordAuthentication( ) always returns
null. To create an
Authenticator, you must override this method so
that it prompts the user to enter a username and password and returns
that information in the form of a
PasswordAuthentication object. Your implementation
of getPasswordAuthentication( ) may call the
various getrequesting( ) methods to find out who
is requesting the password and what the recommended user prompt is.
Java 1.4 added a version of the static
requestPasswordAuthentication( ) method that
allows specification of the requesting hostname. A corresponding
getrequestingHost( ) instance method was also
added.
Java 5.0 adds yet another version of
requestPasswordAuthentication( ), and
corresponding methods to query the URL that
requires the password and the RequestorType of the
request. RequestorType is a nested enum type that
specifies whether the request comes from an HTTP server or a proxy
server.
public abstract class Authenticator {
// Public Constructors
public Authenticator( );
// Nested Types
5.0 public enum RequestorType;
// Public Class Methods
public static PasswordAuthentication requestPasswordAuthentication
(InetAddress addr, int port, String protocol,
String prompt, String scheme);
1.4 public static PasswordAuthentication requestPasswordAuthentication
(String host, InetAddress addr, int port, String protocol,
String prompt, String scheme);
5.0 public static PasswordAuthentication
requestPasswordAuthentication(String host,
InetAddress addr, int port, String protocol, String prompt,
String scheme, URL url, Authenticator.RequestorType reqType);
public static void setDefault(Authenticator a); synchronized
// Protected Instance Methods
protected PasswordAuthentication getPasswordAuthentication( ); constant
1.4 protected final String getRequestingHost( );
protected final int getRequestingPort( );
protected final String getRequestingPrompt( );
protected final String getRequestingProtocol( );
protected final String getRequestingScheme( );
protected final InetAddress getRequestingSite( );
5.0 protected URL getRequestingURL( );
5.0 protected Authenticator.RequestorType getRequestorType( );
}