Package java.net
Class Authenticator
- java.lang.Object
-
- java.net.Authenticator
-
public abstract class Authenticator extends Object
An implementation of this class is able to obtain authentication information for a connection in several ways. For this purpose it has to set the default authenticator which extendsAuthenticatorbysetDefault(Authenticator a). Then it should overridegetPasswordAuthentication()which dictates how the authentication info is obtained. Usually, it prompts the user for the required input.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAuthenticator.RequestorTypeEnumeration class for the origin of the authentication request.
-
Constructor Summary
Constructors Constructor Description Authenticator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PasswordAuthenticationgetPasswordAuthentication()Returns the collected username and password for authorization.protected StringgetRequestingHost()Returns the host name of the connection that requests authentication ornullif unknown.protected intgetRequestingPort()Returns the port of the connection that requests authorization.protected StringgetRequestingPrompt()Returns the realm (prompt string) of the connection that requests authorization.protected StringgetRequestingProtocol()Returns the protocol of the connection that requests authorization.protected StringgetRequestingScheme()Returns the scheme of the connection that requests authorization, for example HTTP Basic Authentication.protected InetAddressgetRequestingSite()Returns the address of the connection that requests authorization ornullif unknown.protected URLgetRequestingURL()Returns the URL of the authentication request.protected Authenticator.RequestorTypegetRequestorType()Returns the type of this request, it can bePROXYorSERVER.static PasswordAuthenticationrequestPasswordAuthentication(String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)Invokes the methods of the registered authenticator to get the authentication info.static PasswordAuthenticationrequestPasswordAuthentication(String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme, URL rURL, Authenticator.RequestorType reqType)Invokes the methods of the registered authenticator to get the authentication info.static PasswordAuthenticationrequestPasswordAuthentication(InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)Invokes the methods of the registered authenticator to get the authentication info.static voidsetDefault(Authenticator a)Setsaas the default authenticator.
-
-
-
Method Detail
-
getPasswordAuthentication
protected PasswordAuthentication getPasswordAuthentication()
Returns the collected username and password for authorization. The subclass has to override this method to return a value different to the default which isnull.Returns
nullby default.- Returns:
- collected password authentication data.
-
getRequestingPort
protected final int getRequestingPort()
Returns the port of the connection that requests authorization.- Returns:
- port of the connection.
-
getRequestingSite
protected final InetAddress getRequestingSite()
Returns the address of the connection that requests authorization ornullif unknown.- Returns:
- address of the connection.
-
getRequestingPrompt
protected final String getRequestingPrompt()
Returns the realm (prompt string) of the connection that requests authorization.- Returns:
- prompt string of the connection.
-
getRequestingProtocol
protected final String getRequestingProtocol()
Returns the protocol of the connection that requests authorization.- Returns:
- protocol of the connection.
-
getRequestingScheme
protected final String getRequestingScheme()
Returns the scheme of the connection that requests authorization, for example HTTP Basic Authentication.- Returns:
- scheme of the connection.
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)
Invokes the methods of the registered authenticator to get the authentication info.- Parameters:
rAddr- address of the connection that requests authentication.rPort- port of the connection that requests authentication.rProtocol- protocol of the connection that requests authentication.rPrompt- realm of the connection that requests authentication.rScheme- scheme of the connection that requests authentication.- Returns:
- password authentication info or
nullif no authenticator exists.
-
setDefault
public static void setDefault(Authenticator a)
Setsaas the default authenticator. It will be called whenever the realm that the URL is pointing to requires authorization.- Parameters:
a- authenticator which has to be set as default.
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)
Invokes the methods of the registered authenticator to get the authentication info.- Parameters:
rHost- host name of the connection that requests authentication.rAddr- address of the connection that requests authentication.rPort- port of the connection that requests authentication.rProtocol- protocol of the connection that requests authentication.rPrompt- realm of the connection that requests authentication.rScheme- scheme of the connection that requests authentication.- Returns:
- password authentication info or
nullif no authenticator exists.
-
getRequestingHost
protected final String getRequestingHost()
Returns the host name of the connection that requests authentication ornullif unknown.- Returns:
- name of the requesting host or
null.
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme, URL rURL, Authenticator.RequestorType reqType)
Invokes the methods of the registered authenticator to get the authentication info.- Parameters:
rHost- host name of the connection that requests authentication.rAddr- address of the connection that requests authentication.rPort- port of the connection that requests authentication.rProtocol- protocol of the connection that requests authentication.rPrompt- realm of the connection that requests authentication.rScheme- scheme of the connection that requests authentication.rURL- url of the connection that requests authentication.reqType- requestor type of the connection that requests authentication.- Returns:
- password authentication info or
nullif no authenticator exists.
-
getRequestingURL
protected URL getRequestingURL()
Returns the URL of the authentication request.- Returns:
- authentication request url.
-
getRequestorType
protected Authenticator.RequestorType getRequestorType()
Returns the type of this request, it can bePROXYorSERVER.- Returns:
- RequestorType of the authentication request.
-
-