java.lang.Object | |
↳ | java.net.Authenticator |
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 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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Authenticator.RequestorType | The type of the entity requesting authentication. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Ask the authenticator that has been registered with the system
for a password.
| |||||||||||
Ask the authenticator that has been registered with the system
for a password.
| |||||||||||
Ask the authenticator that has been registered with the system
for a password.
| |||||||||||
Sets the authenticator that will be used by the networking code
when a proxy or an HTTP server asks for authentication.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called when password authorization is needed.
| |||||||||||
Gets the
hostname of the
site or proxy requesting authentication, or null
if not available. | |||||||||||
Gets the port number for the requested connection.
| |||||||||||
Gets the prompt string given by the requestor.
| |||||||||||
Give the protocol that's requesting the connection.
| |||||||||||
Gets the scheme of the requestor (the HTTP scheme
for an HTTP firewall, for example).
| |||||||||||
Gets the
InetAddress of the
site requesting authorization, or null
if not available. | |||||||||||
Returns the URL that resulted in this
request for authentication.
| |||||||||||
Returns whether the requestor is a Proxy or a Server.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
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.
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 |
SecurityException | if a security manager exists and its
checkPermission method doesn't allow
the password authentication request. |
---|
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.
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. |
SecurityException | if a security manager exists and its
checkPermission method doesn't allow
the password authentication request. |
---|
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.
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 |
SecurityException | if a security manager exists and its
checkPermission method doesn't allow
the password authentication request. |
---|
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.
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. |
---|
Called when password authorization is needed. Subclasses should override the default implementation, which returns null.
Gets the hostname
of the
site or proxy requesting authentication, or null
if not available.
Gets the port number for the requested connection.
int
indicating the
port for the requested connection.
Gets the prompt string given by the requestor.
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.
Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).
Gets the InetAddress
of the
site requesting authorization, or null
if not available.
Returns the URL that resulted in this request for authentication.
Returns whether the requestor is a Proxy or a Server.