com.dtolabs.client.utils
Class BaseFormAuthenticator

java.lang.Object
  extended by com.dtolabs.client.utils.BaseFormAuthenticator
All Implemented Interfaces:
HttpAuthenticator
Direct Known Subclasses:
WebserviceFormAuthenticator

public abstract class BaseFormAuthenticator
extends java.lang.Object
implements HttpAuthenticator

BaseFormAuthenticator provides base implementation of authenticator by posting login information to the j_security_check authorization mechanism. If a 401 UNAUTHORIZED response is detected, then authentication is passed on to the BasicAuthenticator. This class is abstract and all abstract methods should be implemented by subclasses:


Field Summary
static java.lang.String HTTP_SECURE_PROTOCOL
          Secure protocol: "https"
static java.lang.String J_SECURITY_CHECK
           
static java.lang.String JAVA_AUTH_PATH
          path for java auth form submit: "/j_security_check"
static java.lang.String JAVA_PASS_PARAM
          password param for java auth form submit: "j_password"
static java.lang.String JAVA_SESSION_COOKIE_NAME
          Cookie name for java auth session: "JSESSIONID"
static java.util.regex.Pattern JAVA_SESSION_COOKIE_PATTERN
           
static java.lang.String JAVA_USER_PARAM
          username param for java auth form submit: "j_username"
static org.apache.log4j.Logger logger
          logger
static java.lang.String LOGIN_PAGE
          Text to check Location of redirects to indicate login is required.
 
Constructor Summary
BaseFormAuthenticator(java.lang.String basePath, java.lang.String username, java.lang.String password)
          Constructor with base URL path, username and password for authentication.
 
Method Summary
 boolean authenticate(java.net.URL baseURL, org.apache.commons.httpclient.HttpClient client)
          Authenticate the client http state so that the colony requests can be made.
 java.lang.String getBasePath()
           
 java.lang.String getCookieId()
           
 java.lang.String getUsername()
          Gets the user login name used when instantiating the authenticator
static boolean hasSessionCookie(java.net.URL reqUrl, org.apache.commons.httpclient.HttpState state, java.lang.String basePath)
          Check the http state cookies to see if we have the proper session id cookie
 boolean needsReAuthentication(int resultCode, org.apache.commons.httpclient.HttpMethod method)
          Return true if the result from the get method indicates re-authentication is needed
 void setCookieId(java.lang.String cookieId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static final org.apache.log4j.Logger logger
logger


J_SECURITY_CHECK

public static final java.lang.String J_SECURITY_CHECK
See Also:
Constant Field Values

JAVA_AUTH_PATH

public static final java.lang.String JAVA_AUTH_PATH
path for java auth form submit: "/j_security_check"

See Also:
Constant Field Values

JAVA_USER_PARAM

public static final java.lang.String JAVA_USER_PARAM
username param for java auth form submit: "j_username"

See Also:
Constant Field Values

JAVA_PASS_PARAM

public static final java.lang.String JAVA_PASS_PARAM
password param for java auth form submit: "j_password"

See Also:
Constant Field Values

JAVA_SESSION_COOKIE_NAME

public static final java.lang.String JAVA_SESSION_COOKIE_NAME
Cookie name for java auth session: "JSESSIONID"

See Also:
Constant Field Values

JAVA_SESSION_COOKIE_PATTERN

public static final java.util.regex.Pattern JAVA_SESSION_COOKIE_PATTERN

HTTP_SECURE_PROTOCOL

public static final java.lang.String HTTP_SECURE_PROTOCOL
Secure protocol: "https"

See Also:
Constant Field Values

LOGIN_PAGE

public static final java.lang.String LOGIN_PAGE
Text to check Location of redirects to indicate login is required.

See Also:
Constant Field Values
Constructor Detail

BaseFormAuthenticator

public BaseFormAuthenticator(java.lang.String basePath,
                             java.lang.String username,
                             java.lang.String password)
Constructor with base URL path, username and password for authentication.

Parameters:
basePath - base URL path to use with the server
username - username to use
password - password to use
Method Detail

authenticate

public boolean authenticate(java.net.URL baseURL,
                            org.apache.commons.httpclient.HttpClient client)
                     throws HttpClientException
Authenticate the client http state so that the colony requests can be made.

Specified by:
authenticate in interface HttpAuthenticator
Parameters:
baseURL - URL requested for colony
client - HttpClient instance
Returns:
true if authentication succeeded.
Throws:
HttpClientException

hasSessionCookie

public static boolean hasSessionCookie(java.net.URL reqUrl,
                                       org.apache.commons.httpclient.HttpState state,
                                       java.lang.String basePath)
Check the http state cookies to see if we have the proper session id cookie

Parameters:
reqUrl - URL being requested
state - HTTP state object
basePath - base path of requests
Returns:
true if a cookie matching the basePath, server host and port, and request protocol and appropriate session cookie name is found

needsReAuthentication

public boolean needsReAuthentication(int resultCode,
                                     org.apache.commons.httpclient.HttpMethod method)
Return true if the result from the get method indicates re-authentication is needed

Specified by:
needsReAuthentication in interface HttpAuthenticator
Parameters:
resultCode - result code
method - request
Returns:
true if re-authentication is needed

getUsername

public java.lang.String getUsername()
Description copied from interface: HttpAuthenticator
Gets the user login name used when instantiating the authenticator

Specified by:
getUsername in interface HttpAuthenticator
Returns:
Login name

getBasePath

public java.lang.String getBasePath()

getCookieId

public java.lang.String getCookieId()

setCookieId

public void setCookieId(java.lang.String cookieId)