Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public abstract class

Authenticator

extends Object
java.lang.Object
   ↳ java.net.Authenticator

Class Overview

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.

Summary

Nested Classes
enum Authenticator.RequestorType Enumeration class for the origin of the authentication request. 
Public Constructors
Authenticator ()
Public Methods
synchronized 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.
synchronized 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 .
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Authenticator ()

Added in API level 1

Public Methods

public static synchronized PasswordAuthentication requestPasswordAuthentication ( String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)

Added in API level 1

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 null if no authenticator exists.

public static PasswordAuthentication requestPasswordAuthentication ( String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme, URL rURL, Authenticator.RequestorType reqType)

Added in API level 1

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 null if no authenticator exists.

public static synchronized PasswordAuthentication requestPasswordAuthentication ( InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)

Added in API level 1

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 null if no authenticator exists.

public static void setDefault ( Authenticator a)

Added in API level 1

Sets a as 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.

Protected Methods

protected PasswordAuthentication getPasswordAuthentication ()

Added in API level 1

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
  • collected password authentication data.

protected final String getRequestingHost ()

Added in API level 1

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

Returns
  • name of the requesting host or null .

protected final int getRequestingPort ()

Added in API level 1

Returns the port of the connection that requests authorization.

Returns
  • port of the connection.

protected final String getRequestingPrompt ()

Added in API level 1

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

Returns
  • prompt string of the connection.

protected final String getRequestingProtocol ()

Added in API level 1

Returns the protocol of the connection that requests authorization.

Returns
  • protocol of the connection.

protected final String getRequestingScheme ()

Added in API level 1

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

Returns
  • scheme of the connection.

protected final InetAddress getRequestingSite ()

Added in API level 1

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

Returns
  • address of the connection.

protected URL getRequestingURL ()

Added in API level 1

Returns the URL of the authentication request.

Returns
  • authentication request url.

protected Authenticator.RequestorType getRequestorType ()

Added in API level 1

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

Returns
  • RequestorType of the authentication request.