Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Authenticator

public abstract class Authenticator
extends Object

java.lang.Object
   ↳ java.net.Authenticator


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 extends Authenticator by setDefault(Authenticator a). Then it should override getPasswordAuthentication() which dictates how the authentication info is obtained. Usually, it prompts the user for the required input.

See also:

Summary

Nested classes

enum Authenticator.RequestorType

Enumeration class for the origin of the authentication request. 

Public constructors

Authenticator()

Public methods

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.

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.

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.

static void setDefault(Authenticator a)

Sets a as the default authenticator.

Protected methods

PasswordAuthentication getPasswordAuthentication()

Returns the collected username and password for authorization.

final String getRequestingHost()

Returns the host name of the connection that requests authentication or null if unknown.

final int getRequestingPort()

Returns the port of the connection that requests authorization.

final String getRequestingPrompt()

Returns the realm (prompt string) of the connection that requests authorization.

final String getRequestingProtocol()

Returns the protocol of the connection that requests authorization.

final String getRequestingScheme()

Returns the scheme of the connection that requests authorization, for example HTTP Basic Authentication.

final InetAddress getRequestingSite()

Returns the address of the connection that requests authorization or null if unknown.

URL getRequestingURL()

Returns the URL of the authentication request.

Authenticator.RequestorType getRequestorType()

Returns the type of this request, it can be PROXY or SERVER.

Inherited methods

From class java.lang.Object

Public constructors

Authenticator

Added in API level 1
Authenticator ()

Public methods

requestPasswordAuthentication

Added in API level 1
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 String: host name of the connection that requests authentication.
rAddr InetAddress: address of the connection that requests authentication.
rPort int: port of the connection that requests authentication.
rProtocol String: protocol of the connection that requests authentication.
rPrompt String: realm of the connection that requests authentication.
rScheme String: scheme of the connection that requests authentication.
Returns
PasswordAuthentication password authentication info or null if no authenticator exists.

requestPasswordAuthentication

Added in API level 1
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 String: host name of the connection that requests authentication.
rAddr InetAddress: address of the connection that requests authentication.
rPort int: port of the connection that requests authentication.
rProtocol String: protocol of the connection that requests authentication.
rPrompt String: realm of the connection that requests authentication.
rScheme String: scheme of the connection that requests authentication.
rURL URL: url of the connection that requests authentication.
reqType Authenticator.RequestorType: requestor type of the connection that requests authentication.
Returns
PasswordAuthentication password authentication info or null if no authenticator exists.

requestPasswordAuthentication

Added in API level 1
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 InetAddress: address of the connection that requests authentication.
rPort int: port of the connection that requests authentication.
rProtocol String: protocol of the connection that requests authentication.
rPrompt String: realm of the connection that requests authentication.
rScheme String: scheme of the connection that requests authentication.
Returns
PasswordAuthentication password authentication info or null if no authenticator exists.

setDefault

Added in API level 1
void setDefault (Authenticator a)

Sets a as the default authenticator. It will be called whenever the realm that the URL is pointing to requires authorization.

Parameters
a Authenticator: authenticator which has to be set as default.

Protected methods

getPasswordAuthentication

Added in API level 1
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 is null.

Returns null by default.

Returns
PasswordAuthentication collected password authentication data.

getRequestingHost

Added in API level 1
String getRequestingHost ()

Returns the host name of the connection that requests authentication or null if unknown.

Returns
String name of the requesting host or null.

getRequestingPort

Added in API level 1
int getRequestingPort ()

Returns the port of the connection that requests authorization.

Returns
int port of the connection.

getRequestingPrompt

Added in API level 1
String getRequestingPrompt ()

Returns the realm (prompt string) of the connection that requests authorization.

Returns
String prompt string of the connection.

getRequestingProtocol

Added in API level 1
String getRequestingProtocol ()

Returns the protocol of the connection that requests authorization.

Returns
String protocol of the connection.

getRequestingScheme

Added in API level 1
String getRequestingScheme ()

Returns the scheme of the connection that requests authorization, for example HTTP Basic Authentication.

Returns
String scheme of the connection.

getRequestingSite

Added in API level 1
InetAddress getRequestingSite ()

Returns the address of the connection that requests authorization or null if unknown.

Returns
InetAddress address of the connection.

getRequestingURL

Added in API level 1
URL getRequestingURL ()

Returns the URL of the authentication request.

Returns
URL authentication request url.

getRequestorType

Added in API level 1
Authenticator.RequestorType getRequestorType ()

Returns the type of this request, it can be PROXY or SERVER.

Returns
Authenticator.RequestorType RequestorType of the authentication request.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.