se.entra.phantom.auth
Class Auth

java.lang.Object
  extended by java.net.Authenticator
      extended by se.entra.phantom.auth.Auth

public class Auth
extends Authenticator

This class handles user authentication for HTTP/HTTPS connections as well as password processing for SSL certificate files. It also provides a method of passing the current userid/passwords or certificate file password entries for another process, e.g. between NetPhantom Starters and/or NetPhantom Client in order to avoid entering the same UserID/password or just the SSL certificate password again in the new process.

This class sets and handles the Authenticator for HTTP and HTTPS connections in Java 2. For HTTPS this is only supported in JDK 1.4.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.net.Authenticator
Authenticator.RequestorType
 
Constructor Summary
Auth(AuthCB callBack)
          Creates the instance of the NetPhantom Authenticator.
 
Method Summary
 void addCA(String text)
          Adds a CA certificate as accepted for this session.
 void addCertPW(String fileName, String password)
          Requests for a password for a client certificate file.
static Auth getAuth()
          Gets the single authenticator instance.
 String[] getAuth(boolean usesSSL, String serverName, String scheme, String realm)
          Requests a password.
 Hashtable<String,String> getAuthHeaderTable(Vector headers, String proxyHost)
          Gets a hashtable with token and value pairs from the authentication or proxy authentication header field string.
 String getAuthString(String method, String protocol, String host, int port, String file, Hashtable<String,String> serverAuth, String proxyHost)
          Requests the authentication header field required to connect to the server in question.
 String getAuthString(String method, URLConnection uc, String proxyHost)
          Requests the authentication header field required to connect to the server in question.
 String getAuthString(String method, URL url, Hashtable<String,String> serverAuth, String proxyHost)
          Requests the authentication header field required to connect to the server in question.
 String getAuthString(String method, URL url, String proxyHost)
          Requests the authentication header field required to based on a previous successful call for this server.
 String getCertPW(String fileName)
          Requests for a password for a client certificate file.
 String[] getCurrentAuthString(String serverName, String realm)
          Gets the current authentication, if such exists.
static Hashtable<String,String> getFieldValues(String line)
          Gets a hashtable with token and value pairs from a header field string.
 String getParams()
          Creates the string that can be used to pass parameters between a process that has already some definitions of UserID/passwords or just passwords.
protected  PasswordAuthentication getPasswordAuthentication()
          Called when password authorization is needed.
 void initParams(String params)
          Initiates the table of previous UserID/password definitions for a server (+ possible realm) or just a file name (for certificate files) from another process.
 boolean isAcceptedCA(String text)
          Checks if a CA certificate is already accepted for this session.
 
Methods inherited from class java.net.Authenticator
getRequestingHost, getRequestingPort, getRequestingPrompt, getRequestingProtocol, getRequestingScheme, getRequestingSite, getRequestingURL, getRequestorType, requestPasswordAuthentication, requestPasswordAuthentication, requestPasswordAuthentication, setDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Auth

public Auth(AuthCB callBack)
Creates the instance of the NetPhantom Authenticator.

Parameters:
callBack - the callBack interface implementor when a request for userID/password is requested.
Method Detail

getAuth

public static Auth getAuth()
Gets the single authenticator instance.

Returns:
null if the authenticator is not yet created.

getFieldValues

public static Hashtable<String,String> getFieldValues(String line)
Gets a hashtable with token and value pairs from a header field string.

Returns:
Hashtable of token value pairs from header field string.

getCertPW

public String getCertPW(String fileName)
Requests for a password for a client certificate file.


addCertPW

public void addCertPW(String fileName,
                      String password)
Requests for a password for a client certificate file.


addCA

public void addCA(String text)
Adds a CA certificate as accepted for this session.


isAcceptedCA

public boolean isAcceptedCA(String text)
Checks if a CA certificate is already accepted for this session.


initParams

public void initParams(String params)
Initiates the table of previous UserID/password definitions for a server (+ possible realm) or just a file name (for certificate files) from another process.


getParams

public String getParams()
Creates the string that can be used to pass parameters between a process that has already some definitions of UserID/passwords or just passwords.

The data is separated with '/' between each element and the element key/data is separated with '-'.

Returns:
null if no data exists that needs storing.

getAuth

public String[] getAuth(boolean usesSSL,
                        String serverName,
                        String scheme,
                        String realm)
Requests a password. Before calling the registered callback, the table of current UserID/password entries will be checked, and if there is an entry, this one will be returned (once only).

The following parameters indicates how the process is handled:

Returns:
null no userID/password is specified (cancel was pressed. String [2] String[0]=userID, String[1]=password, for certificate files, userID is null.

getAuthString

public String getAuthString(String method,
                            URL url,
                            String proxyHost)
Requests the authentication header field required to based on a previous successful call for this server.


getAuthString

public String getAuthString(String method,
                            URLConnection uc,
                            String proxyHost)
Requests the authentication header field required to connect to the server in question.

Returns:
null when no authentication header is possible, or if the user canceled the userID/password dialog box.

getAuthHeaderTable

public Hashtable<String,String> getAuthHeaderTable(Vector headers,
                                                   String proxyHost)
Gets a hashtable with token and value pairs from the authentication or proxy authentication header field string.


getAuthString

public String getAuthString(String method,
                            String protocol,
                            String host,
                            int port,
                            String file,
                            Hashtable<String,String> serverAuth,
                            String proxyHost)
Requests the authentication header field required to connect to the server in question.

Returns:
null when no authentication header is possible, or if the user canceled the userID/password dialog box.

getCurrentAuthString

public String[] getCurrentAuthString(String serverName,
                                     String realm)
Gets the current authentication, if such exists. This entry is deleted from the table to make the system prompt for authorization.

Parameters:
String - - server name
String - - realm
Returns:
String[] - String array holding user name and password (in that order)

getAuthString

public String getAuthString(String method,
                            URL url,
                            Hashtable<String,String> serverAuth,
                            String proxyHost)
Requests the authentication header field required to connect to the server in question.

Returns:
null when no authentication header is possible, or if the user canceled the userID/password dialog box.

getPasswordAuthentication

protected PasswordAuthentication getPasswordAuthentication()
Called when password authorization is needed. Subclasses should override the default implementation, which returns null (no UserID/password available).

Overrides:
getPasswordAuthentication in class Authenticator
Returns:
The PasswordAuthentication collected from the user, or null if none is provided.


Phantom® and NetPhantom® are registered trademarks of Codectica Systems SARL.
© Copyright Codectica Systems SARL, 2008. All rights reserved.