FileDocCategorySizeDatePackage
Authenticator.javaAPI DocAndroid 1.5 API12141Wed May 06 22:41:04 BST 2009java.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 extends {@code Authenticator} by {@code setDefault(Authenticator a)}. Then it should override {@code getPasswordAuthentication()} which dictates how the authentication info is obtained. Usually, it prompts the user for the required input.
see
#setDefault
see
#getPasswordAuthentication
since
Android 1.0

Fields Summary
private static Authenticator
thisAuthenticator
private static final NetPermission
requestPasswordAuthenticationPermission
private static final NetPermission
setDefaultAuthenticatorPermission
private String
host
private InetAddress
addr
private int
port
private String
protocol
private String
prompt
private String
scheme
private URL
url
private RequestorType
rt
Constructors Summary
Methods Summary
protected java.net.PasswordAuthenticationgetPasswordAuthentication()
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 {@code null}.

Returns {@code null} by default.

return
collected password authentication data.
since
Android 1.0


                                                    
       
        return null;
    
protected final java.lang.StringgetRequestingHost()
Returns the host name of the connection that requests authentication or {@code null} if unknown.

return
name of the requesting host or {@code null}.
since
Android 1.0

        return host;
    
protected final intgetRequestingPort()
Returns the port of the connection that requests authorization.

return
port of the connection.
since
Android 1.0

        return this.port;
    
protected final java.lang.StringgetRequestingPrompt()
Returns the realm (prompt string) of the connection that requests authorization.

return
prompt string of the connection.
since
Android 1.0

        return this.prompt;
    
protected final java.lang.StringgetRequestingProtocol()
Returns the protocol of the connection that requests authorization.

return
protocol of the connection.
since
Android 1.0

        return this.protocol;
    
protected final java.lang.StringgetRequestingScheme()
Returns the scheme of the connection that requests authorization, for example HTTP Basic Authentication.

return
scheme of the connection.
since
Android 1.0

        return this.scheme;
    
protected final java.net.InetAddressgetRequestingSite()
Returns the address of the connection that requests authorization or {@code null} if unknown.

return
address of the connection.
since
Android 1.0

        return this.addr;
    
protected java.net.URLgetRequestingURL()
Returns the URL of the authentication request.

return
authentication request url.
since
Android 1.0

        return url;
    
protected java.net.Authenticator$RequestorTypegetRequestorType()
Returns the type of this request, it can be {@code PROXY} or {@code SERVER}.

return
RequestorType of the authentication request.
since
Android 1.0

        return rt;
    
public static java.net.PasswordAuthenticationrequestPasswordAuthentication(java.lang.String rHost, java.net.InetAddress rAddr, int rPort, java.lang.String rProtocol, java.lang.String rPrompt, java.lang.String rScheme, java.net.URL rURL, java.net.Authenticator$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.

return
password authentication info or {@code null} if no authenticator exists.
param
rHost host name of the connection that requests authentication.
param
rAddr address of the connection that requests authentication.
param
rPort port of the connection that requests authentication.
param
rProtocol protocol of the connection that requests authentication.
param
rPrompt realm of the connection that requests authentication.
param
rScheme scheme of the connection that requests authentication.
param
rURL url of the connection that requests authentication.
param
reqType requestor type of the connection that requests authentication.
throws
SecurityException if a security manager denies the password authentication permission.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (null != sm) {
            sm.checkPermission(requestPasswordAuthenticationPermission);
        }
        if (null == thisAuthenticator) {
            return null;
        }
        // sets the requester info so it knows what it is requesting
        // authentication for
        thisAuthenticator.host = rHost;
        thisAuthenticator.addr = rAddr;
        thisAuthenticator.port = rPort;
        thisAuthenticator.protocol = rProtocol;
        thisAuthenticator.prompt = rPrompt;
        thisAuthenticator.scheme = rScheme;
        thisAuthenticator.url = rURL;
        thisAuthenticator.rt = reqType;

        // returns the authentication info obtained by the registered
        // Authenticator
        return thisAuthenticator.getPasswordAuthentication();

    
public static synchronized java.net.PasswordAuthenticationrequestPasswordAuthentication(java.net.InetAddress rAddr, int rPort, java.lang.String rProtocol, java.lang.String rPrompt, java.lang.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.

return
password authentication info or {@code null} if no authenticator exists.
param
rAddr address of the connection that requests authentication.
param
rPort port of the connection that requests authentication.
param
rProtocol protocol of the connection that requests authentication.
param
rPrompt realm of the connection that requests authentication.
param
rScheme scheme of the connection that requests authentication.
throws
SecurityException if a security manager denies the password authentication permission.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(requestPasswordAuthenticationPermission);
        }
        if (thisAuthenticator == null) {
            return null;
        }
        // set the requester info so it knows what it is requesting
        // authentication for
        thisAuthenticator.addr = rAddr;
        thisAuthenticator.port = rPort;
        thisAuthenticator.protocol = rProtocol;
        thisAuthenticator.prompt = rPrompt;
        thisAuthenticator.scheme = rScheme;
        thisAuthenticator.rt = RequestorType.SERVER;

        // returns the authentication info obtained by the registered
        // Authenticator
        return thisAuthenticator.getPasswordAuthentication();
    
public static synchronized java.net.PasswordAuthenticationrequestPasswordAuthentication(java.lang.String rHost, java.net.InetAddress rAddr, int rPort, java.lang.String rProtocol, java.lang.String rPrompt, java.lang.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.

return
password authentication info or {@code null} if no authenticator exists.
param
rHost host name of the connection that requests authentication.
param
rAddr address of the connection that requests authentication.
param
rPort port of the connection that requests authentication.
param
rProtocol protocol of the connection that requests authentication.
param
rPrompt realm of the connection that requests authentication.
param
rScheme scheme of the connection that requests authentication.
throws
SecurityException if a security manager denies the password authentication permission.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(requestPasswordAuthenticationPermission);
        }
        if (thisAuthenticator == null) {
            return null;
        }
        // set the requester info so it knows what it is requesting
        // authentication for
        thisAuthenticator.host = rHost;
        thisAuthenticator.addr = rAddr;
        thisAuthenticator.port = rPort;
        thisAuthenticator.protocol = rProtocol;
        thisAuthenticator.prompt = rPrompt;
        thisAuthenticator.scheme = rScheme;
        thisAuthenticator.rt = RequestorType.SERVER;

        // returns the authentication info obtained by the registered
        // Authenticator
        return thisAuthenticator.getPasswordAuthentication();
    
public static voidsetDefault(java.net.Authenticator a)
Sets {@code a} as 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 appropriate {@code NetPermission}.

param
a authenticator which has to be set as default.
throws
SecurityException if a security manager denies the password authentication permission.
since
Android 1.0

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(setDefaultAuthenticatorPermission);
        }
        thisAuthenticator = a;