Java Platform 1.2
Beta 4

Class java.net.Authenticator

java.lang.Object
  |
  +--java.net.Authenticator

public abstract class Authenticator
extends Object
The class Authenticator represents an object that knows how to obtain authentication for a network connection. Usually, it will do this by prompting the user for information.

Applications use this class by creating a subclass, and registering an instance of that subclass with the system with setDefault(). When authentication is required, the system will invoke a method on the subclass (like getPasswordAuthentication). The subclass's method can query about the authentication being requested with a number of inherited methods (getRequestingXXX()), and form an appropriate message for the user.

All methods that request authentication have a default implementation that fails.

Since:
JDK1.2
See Also:
java.net.Authenticator.setDefault(java.net.ConnectionAuthenticator), java.net.getPasswordAuthentication()

Method Summary
protected  PasswordAuthentication getPasswordAuthentication()
          Called when password authorization is needed.
protected  int getRequestingPort()
           
protected  String getRequestingPrompt()
           
protected  String getRequestingProtocol()
          Give the protocol that's requesting the connection.
protected  String getRequestingScheme()
           
protected  InetAddress getRequestingSite()
           
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.
static void setDefault(Authenticator a)
          Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authenticator.
 
Methods inherited from class java.lang.Object
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait
 

Method Detail

setDefault

public static void setDefault(Authenticator a)
Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authenticator. If an Authenticator has already been established as the current authenticator, no action will be taken. If the argument is null and no authenticator has been established, then no action is taken and the method simply returns.

If the caller does not have the java.net.Net "setDefaultAuthenticator" permission, then a java.lang.SecurityException will be thrown.

Typically, this will be called exactly once, at system startup.

Parameters:
a - The authenticator

requestPasswordAuthentication

public 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.

If the caller does not have java.net.Net "requestPasswordAuthentication" permission, a java.lang.SecurityException will be thrown.

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 (@see java.net.Authenticator.getProtocol())
prompt - A prompt string for the user
scheme - The authentication scheme
Returns:
The username/password, or null if one can't be gotten.

getRequestingSite

protected final InetAddress getRequestingSite()
Returns:
the InetAddress of the site requesting authorization, or null if it's not available.

getRequestingPort

protected final int getRequestingPort()
Returns:
the port for the requested connection

getRequestingProtocol

protected final String getRequestingProtocol()
Give 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 protcol, optionally followed by "/version", where version is a version number.
See Also:
java.net.URL.getProtocol()

getRequestingPrompt

protected final String getRequestingPrompt()
Returns:
the prompt string given by the requestor (realm for http requests)

getRequestingScheme

protected final String getRequestingScheme()
Returns:
the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example)

getPasswordAuthentication

protected PasswordAuthentication getPasswordAuthentication()
Called 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.

Java Platform 1.2
Beta 4

Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.