Class Authenticator
public abstract class Authenticator extends Object
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 Summary
| Modifier and Type | Class | Description |
|---|---|---|
static enum |
Authenticator.RequestorType |
The type of the entity requesting authentication. |
Constructor Summary
| Constructor | Description |
|---|---|
Authenticator() |
Constructor for subclasses to call. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
static Authenticator |
getDefault() |
Gets the default authenticator. |
protected PasswordAuthentication |
getPasswordAuthentication() |
Called when password authorization is needed. |
protected final String |
getRequestingHost() |
Gets the hostname of the site or proxy requesting authentication, or null if not available. |
protected final int |
getRequestingPort() |
Gets the port number for the requested connection. |
protected final String |
getRequestingPrompt() |
Gets the prompt string given by the requestor. |
protected final String |
getRequestingProtocol() |
Give the protocol that's requesting the connection. |
protected final String |
getRequestingScheme() |
Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example). |
protected final InetAddress |
getRequestingSite() |
Gets the InetAddress of the site requesting authorization, or null if not available. |
protected URL |
getRequestingURL() |
Returns the URL that resulted in this request for authentication. |
protected Authenticator.RequestorType |
getRequestorType() |
Returns whether the requestor is a Proxy or a Server. |
static PasswordAuthentication |
requestPasswordAuthentication |
Ask the authenticator that has been registered with the system for a password. |
static PasswordAuthentication |
requestPasswordAuthentication |
Ask the authenticator that has been registered with the system for a password. |
static PasswordAuthentication |
requestPasswordAuthentication |
Ask the given authenticator for a password. |
static PasswordAuthentication |
requestPasswordAuthentication |
Ask the authenticator that has been registered with the system for a password. |
PasswordAuthentication |
requestPasswordAuthenticationInstance |
Ask this authenticator for a password. |
static void |
setDefault |
Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
Authenticator
public Authenticator()
Method Details
setDefault
public static void setDefault(Authenticator a)
- Parameters:
-
a- The authenticator to be set. If a isnullthen any previously set authenticator is removed.
getDefault
public static Authenticator getDefault()
- Returns:
- The default authenticator, if set,
nullotherwise. - Since:
- 9
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)
- 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.
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)
- 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
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
- 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
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(Authenticator authenticator, String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
authenticator for a password. If the given authenticator is null, the authenticator, if any, that has been registered with the system using setDefault is used.- Parameters:
-
authenticator- the authenticator, ornull. -
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
requestPasswordAuthenticationInstance
public PasswordAuthentication requestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
- 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
getRequestingHost
protected final String getRequestingHost()
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.
- Since:
- 1.4
getRequestingSite
protected final InetAddress getRequestingSite()
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.
getRequestingPort
protected final int getRequestingPort()
- Returns:
- an
intindicating the port for the requested connection.
getRequestingProtocol
protected final String getRequestingProtocol()
- Returns:
- the protocol, optionally followed by "/version", where version is a version number.
- See Also:
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
getPasswordAuthentication
protected PasswordAuthentication getPasswordAuthentication()
- Returns:
- The PasswordAuthentication collected from the user, or null if none is provided.
getRequestingURL
protected URL getRequestingURL()
- Returns:
- the requesting URL, or null if not available.
- Since:
- 1.5
getRequestorType
protected Authenticator.RequestorType getRequestorType()
- Returns:
- the authentication type of the requestor
- Since:
- 1.5
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.