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.
| Modifier and Type | Class | Description | 
|---|---|---|
| static enum  | Authenticator.RequestorType | The type of the entity requesting authentication. | 
| Constructor | Description | 
|---|---|
| Authenticator() | Constructor for subclasses to call. | 
| 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  hostnameof the site or proxy requesting authentication, ornullif 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  InetAddressof the site requesting authorization, ornullif 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  authenticatorfor 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. | 
public Authenticator()
public static void setDefault(Authenticator a)
 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.
a - The authenticator to be set. If a is null then any previously set authenticator is removed.SecurityException - if a security manager exists and its checkPermission method doesn't allow setting the default authenticator.public static Authenticator getDefault()
checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException. Then the default authenticator, if set, is returned. Otherwise, null is returned.null otherwise.SecurityException - if a security manager exists and its checkPermission method doesn't allow requesting password authentication.public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)
 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.
addr - The InetAddress of the site requesting authorization, or null if not known.port - the port for the requested connectionprotocol - The protocol that's requesting the connection (getRequestingProtocol())prompt - A prompt string for the userscheme - The authentication schemeSecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)
 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.
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 schemeSecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
 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.
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 connectionprotocol - The protocol that's requesting the connection (getRequestingProtocol())prompt - A prompt string for the userscheme - The authentication schemeurl - The requesting URL that caused the authenticationreqType - The type (server or proxy) of the entity requesting authentication.SecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.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.  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.
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 connectionprotocol - The protocol that's requesting the connection (getRequestingProtocol())prompt - A prompt string for the userscheme - The authentication schemeurl - The requesting URL that caused the authenticationreqType - The type (server or proxy) of the entity requesting authentication.null if one can't be gotten.SecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.public PasswordAuthentication requestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
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 connectionprotocol - The protocol that's requesting the connection (getRequestingProtocol())prompt - A prompt string for the userscheme - The authentication schemeurl - The requesting URL that caused the authenticationreqType - The type (server or proxy) of the entity requesting authentication.protected final String getRequestingHost()
hostname of the site or proxy requesting authentication, or null if not available.protected final InetAddress getRequestingSite()
InetAddress of the site requesting authorization, or null if not available.protected final int getRequestingPort()
int indicating the port for the requested connection.protected final String getRequestingProtocol()
protected final String getRequestingPrompt()
protected final String getRequestingScheme()
protected PasswordAuthentication getPasswordAuthentication()
protected URL getRequestingURL()
protected Authenticator.RequestorType getRequestorType()
    © 1993, 2023, 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.
    https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/Authenticator.html