Authenticator
abstract class Authenticator
kotlin.Any | |
↳ | 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(java.net.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.
Summary
Nested classes | |
---|---|
The type of the entity requesting authentication. |
Public constructors | |
---|---|
Public methods | |
---|---|
open static PasswordAuthentication! |
requestPasswordAuthentication(host: String!, addr: InetAddress!, port: Int, protocol: String!, prompt: String!, scheme: String!) Ask the authenticator that has been registered with the system for a password. |
open static PasswordAuthentication! |
requestPasswordAuthentication(host: String!, addr: InetAddress!, port: Int, protocol: String!, prompt: String!, scheme: String!, url: URL!, reqType: Authenticator.RequestorType!) Ask the authenticator that has been registered with the system for a password. |
open static PasswordAuthentication! |
requestPasswordAuthentication(addr: InetAddress!, port: Int, protocol: String!, prompt: String!, scheme: String!) Ask the authenticator that has been registered with the system for a password. |
open static Unit |
setDefault(a: Authenticator!) Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication. |
Protected methods | |
---|---|
open PasswordAuthentication! |
Called when password authorization is needed. |
String! |
Gets the |
Int |
Gets the port number for the requested connection. |
String! |
Gets the prompt string given by the requestor. |
String! |
Give the protocol that's requesting the connection. |
String! |
Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example). |
InetAddress! |
Gets the |
open URL! |
Returns the URL that resulted in this request for authentication. |
open Authenticator.RequestorType! |
Returns whether the requestor is a Proxy or a Server. |
Public constructors
Public methods
requestPasswordAuthentication
open static fun requestPasswordAuthentication(
host: String!,
addr: InetAddress!,
port: Int,
protocol: String!,
prompt: String!,
scheme: String!
): PasswordAuthentication!
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 |
String!: The hostname of the site requesting authentication. |
addr |
InetAddress!: The InetAddress of the site requesting authentication, or null if not known. |
port |
Int: the port for the requested connection. |
protocol |
String!: The protocol that's requesting the connection (java.net.Authenticator#getRequestingProtocol() ) |
prompt |
String!: A prompt string for the user which identifies the authentication realm. |
scheme |
String!: The authentication scheme |
Return | |
---|---|
PasswordAuthentication! |
The username/password, or null if one can't be gotten. |
Exceptions | |
---|---|
java.lang.SecurityException |
if a security manager exists and its checkPermission method doesn't allow the password authentication request. |
See Also
requestPasswordAuthentication
open static fun requestPasswordAuthentication(
host: String!,
addr: InetAddress!,
port: Int,
protocol: String!,
prompt: String!,
scheme: String!,
url: URL!,
reqType: Authenticator.RequestorType!
): PasswordAuthentication!
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 |
String!: The hostname of the site requesting authentication. |
addr |
InetAddress!: The InetAddress of the site requesting authorization, or null if not known. |
port |
Int: the port for the requested connection |
protocol |
String!: The protocol that's requesting the connection (java.net.Authenticator#getRequestingProtocol() ) |
prompt |
String!: A prompt string for the user |
scheme |
String!: The authentication scheme |
url |
URL!: The requesting URL that caused the authentication |
reqType |
Authenticator.RequestorType!: The type (server or proxy) of the entity requesting authentication. |
Return | |
---|---|
PasswordAuthentication! |
The username/password, or null if one can't be gotten. |
Exceptions | |
---|---|
java.lang.SecurityException |
if a security manager exists and its checkPermission method doesn't allow the password authentication request. |
See Also
requestPasswordAuthentication
open static fun requestPasswordAuthentication(
addr: InetAddress!,
port: Int,
protocol: String!,
prompt: String!,
scheme: String!
): PasswordAuthentication!
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 |
InetAddress!: The InetAddress of the site requesting authorization, or null if not known. |
port |
Int: the port for the requested connection |
protocol |
String!: The protocol that's requesting the connection (java.net.Authenticator#getRequestingProtocol() ) |
prompt |
String!: A prompt string for the user |
scheme |
String!: The authentication scheme |
Return | |
---|---|
PasswordAuthentication! |
The username/password, or null if one can't be gotten. |
Exceptions | |
---|---|
java.lang.SecurityException |
if a security manager exists and its checkPermission method doesn't allow the password authentication request. |
See Also
setDefault
open static fun setDefault(a: Authenticator!): Unit
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 |
Authenticator!: The authenticator to be set. If a is null then any previously set authenticator is removed. |
Exceptions | |
---|---|
java.lang.SecurityException |
if a security manager exists and its checkPermission method doesn't allow setting the default authenticator. |
See Also
Protected methods
getPasswordAuthentication
protected open fun getPasswordAuthentication(): PasswordAuthentication!
Called when password authorization is needed. Subclasses should override the default implementation, which returns null.
Return | |
---|---|
PasswordAuthentication! |
The PasswordAuthentication collected from the user, or null if none is provided. |
getRequestingHost
protected fun getRequestingHost(): String!
Gets the hostname
of the site or proxy requesting authentication, or null
if not available.
Return | |
---|---|
String! |
the hostname of the connection requiring authentication, or null if it's not available. |
getRequestingPort
protected fun getRequestingPort(): Int
Gets the port number for the requested connection.
Return | |
---|---|
Int |
an int indicating the port for the requested connection. |
getRequestingPrompt
protected fun getRequestingPrompt(): String!
Gets the prompt string given by the requestor.
Return | |
---|---|
String! |
the prompt string given by the requestor (realm for http requests) |
getRequestingProtocol
protected fun getRequestingProtocol(): String!
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.
Return | |
---|---|
String! |
the protocol, optionally followed by "/version", where version is a version number. |
See Also
getRequestingScheme
protected fun getRequestingScheme(): String!
Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).
Return | |
---|---|
String! |
the scheme of the requestor |
getRequestingSite
protected fun getRequestingSite(): InetAddress!
Gets the InetAddress
of the site requesting authorization, or null
if not available.
Return | |
---|---|
InetAddress! |
the InetAddress of the site requesting authorization, or null if it's not available. |
getRequestingURL
protected open fun getRequestingURL(): URL!
Returns the URL that resulted in this request for authentication.
Return | |
---|---|
URL! |
the requesting URL |
getRequestorType
protected open fun getRequestorType(): Authenticator.RequestorType!
Returns whether the requestor is a Proxy or a Server.
Return | |
---|---|
Authenticator.RequestorType! |
the authentication type of the requestor |