This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.net
class Authenticator

java.lang.Object extended by 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 overriding {@link #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 {@link PasswordAuthentication} return value.

An instance of this concrete sub-class is then registered with the system by calling {@link #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.

See Also (auto-generated):

URL

Thread

HttpURLConnection


Nested Class Summary
static enum

           The type of the entity requesting authentication.
 
Constructor Summary

          
 
Method Summary
protected PasswordAuthentication

          Called when password authorization is needed.
protected String

          Gets the hostname of the site or proxy requesting authentication, or null if not available.
protected int

          Gets the port number for the requested connection.
protected String

          Gets the prompt string given by the requestor.
protected String

          Give the protocol that's requesting the connection.
protected String

          Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).
protected InetAddress

          Gets the InetAddress of the site requesting authorization, or null if not available.
protected URL

          Returns the URL that resulted in this request for authentication.
protected Authenticator.RequestorType

          Returns whether the requestor is a Proxy or a Server.
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 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.
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.
static void

          Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Authenticator

public Authenticator()
Method Detail

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.

getRequestingHost

protected final String getRequestingHost()
Gets the hostname of the site or proxy requesting authentication, or null if not available.

Returns:
the hostname of the connection requiring authentication, or null if it's not available.

getRequestingPort

protected final int getRequestingPort()
Gets the port number for the requested connection.

Returns:
an int indicating the port for the requested connection.

getRequestingPrompt

protected final String getRequestingPrompt()
Gets the prompt string given by the requestor.

Returns:
the prompt string given by the requestor (realm for http requests)

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.

getRequestingScheme

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

Returns:
the scheme of the requestor

getRequestingSite

protected final InetAddress getRequestingSite()
Gets the InetAddress of the site requesting authorization, or null if not available.

Returns:
the InetAddress of the site requesting authorization, or null if it's not available.

getRequestingURL

protected URL getRequestingURL()
Returns the URL that resulted in this request for authentication.

Returns:
the requesting URL

getRequestorType

protected Authenticator.RequestorType getRequestorType()
Returns whether the requestor is a Proxy or a Server.

Returns:
the authentication type of the requestor

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.

First, if there is a security manager, its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException.

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

requestPasswordAuthentication

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

First, if there is a security manager, its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException.

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 ({@link java.net.Authenticator#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.

requestPasswordAuthentication

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

First, if there is a security manager, its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException.

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 ({@link java.net.Authenticator#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.

setDefault

public static synchronized void setDefault(Authenticator a)
Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.

First, if there is a security manager, its checkPermission method is called with a NetPermission("setDefaultAuthenticator") permission. This may result in a java.lang.SecurityException.

Parameters:
a - The authenticator to be set. If a is null then any previously set authenticator is removed.


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.