English | Site Directory

Android - An Open Handset Alliance Project

java.net
public abstract class

java.net.Authenticator

java.lang.Object
java.net.Authenticator

This class is able to obtain authentication info for a connection, usually from user. First the application has to set the default authenticator which extends Authenticator by setDefault(Authenticator a).

It should override getPasswordAuthentication() which dictates how the authentication info should be obtained.

Nested Classes
Authenticator.RequestorType an enum class of requestor type  

Summary

Public Constructors

          Authenticator()

Public Methods

  synchronized    static  PasswordAuthentication  requestPasswordAuthentication(String rHost, InetAddress rAddr, int rPort, String rProtocol, String rPrompt, String rScheme)
If the permission check of the security manager does not result in a security exception, this method 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, RequestorType reqType)
If the permission check of the security manager does not result in a security exception, this method 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)
If the permission check of the security manager does not result in a security exception, this method invokes the methods of the registered authenticator to get the authentication info.
      static  void  setDefault(Authenticator a)
This method sets a to be the default authenticator.

Protected Methods

        PasswordAuthentication  getPasswordAuthentication()
This method is responsible for retrieving the username and password for the sender.
    final    String  getRequestingHost()
Return the host name of the connection that requests authentication, or null if unknown.
    final    int  getRequestingPort()
Answers the port of the connection that requests authorization.
    final    String  getRequestingPrompt()
Answers the realm (prompt string) of the connection that requires authorization.
    final    String  getRequestingProtocol()
Answers the protocol of the connection that requests authorization.
    final    String  getRequestingScheme()
Answers the scheme of the connection that requires authorization.
    final    InetAddress  getRequestingSite()
Answers the address of the connection that requests authorization or null if unknown.
        URL  getRequestingURL()
returns the URL of the authentication resulted in this request.
        RequestorType  getRequestorType()
returns the type of this request, it can be proxy or server
Methods inherited from class java.lang.Object

Details

Public Constructors

public Authenticator()

Public Methods

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

If the permission check of the security manager does not result in a security exception, this method invokes the methods of the registered authenticator to get the authentication info.

Parameters

rHost java.lang.String the host name of the connection that requests authentication
rAddr java.net.InetAddress the address of the connection that requests authentication
rPort int the port of the connection that requests authentication
rProtocol java.lang.String the protocol of the connection that requests authentication
rPrompt java.lang.String the realm of the connection that requests authentication
rScheme java.lang.String the scheme of the connection that requests authentication

Returns

  • java.net.PasswordAuthentication the authentication info

Throws

SecurityException if requestPasswordAuthenticationPermission is denied

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

If the permission check of the security manager does not result in a security exception, this method invokes the methods of the registered authenticator to get the authentication info.

Parameters

rHost java.lang.String the host name of the connection that requests authentication
rAddr java.net.InetAddress the address of the connection that requests authentication
rPort int the port of the connection that requests authentication
rProtocol java.lang.String the protocol of the connection that requests authentication
rPrompt java.lang.String the realm of the connection that requests authentication
rScheme java.lang.String the scheme of the connection that requests authentication
rURL java.net.URL the url of the connection that requests authentication
reqType java.net.Authenticator.RequestorType the RequestorType of the connection that requests authentication

Returns

  • java.net.PasswordAuthentication the authentication info

Throws

SecurityException if requestPasswordAuthenticationPermission is denied

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

If the permission check of the security manager does not result in a security exception, this method invokes the methods of the registered authenticator to get the authentication info.

Parameters

rAddr java.net.InetAddress the address of the connection that requests authentication
rPort int the port of the connection that requests authentication
rProtocol java.lang.String the protocol of the connection that requests authentication
rPrompt java.lang.String the realm of the connection that requests authentication
rScheme java.lang.String the scheme of the connection that requests authentication

Returns

  • java.net.PasswordAuthentication the authentication info

Throws

SecurityException if requestPasswordAuthenticationPermission is denied

public static void setDefault(Authenticator a)

This method sets a to be the default authenticator. It will be called whenever the realm that the URL is pointing to requires authorization. If there is a security manager set then the caller must have the NetPermission "setDefaultAuthenticator".

Parameters

a java.net.Authenticator The authenticator to be set.

Throws

SecurityException if requestPasswordAuthenticationPermission is denied

Protected Methods

protected PasswordAuthentication getPasswordAuthentication()

This method is responsible for retrieving the username and password for the sender. The implementation varies. The subclass has to overwrite this.

It answers null by default.

Returns

  • java.net.PasswordAuthentication The password authentication that it obtains

protected final String getRequestingHost()

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

protected final int getRequestingPort()

Answers the port of the connection that requests authorization.

Returns

  • int the port of the connection

protected final String getRequestingPrompt()

Answers the realm (prompt string) of the connection that requires authorization.

Returns

  • java.lang.String the prompt string of the connection

protected final String getRequestingProtocol()

Answers the protocol of the connection that requests authorization.

Returns

  • java.lang.String the protocol of connection

protected final String getRequestingScheme()

Answers the scheme of the connection that requires authorization. Eg. Basic

Returns

  • java.lang.String the scheme of the connection

protected final InetAddress getRequestingSite()

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

Returns

  • InetAddress the address of the connection

protected URL getRequestingURL()

returns the URL of the authentication resulted in this request.

Returns

  • the url of request

protected RequestorType getRequestorType()

returns the type of this request, it can be proxy or server

Returns

  • RequestorType of request
Build m5-rc15i - 10 Jun 2008 13:54