DJDoc v.1.0.0b-1

net.sf.djdoc.app
Class UserStrategy

java.lang.Object
  extended by net.sf.djdoc.app.UserStrategy
Direct Known Subclasses:
ContainerBasedUserStrategy, SameUserStrategy, SimpleUserStrategy

public abstract class UserStrategy
extends java.lang.Object

An abstract class implementing the Strategy design pattern. Its main purpose is authenticating the user for the DJDoc web application. The name of the concrete implementation of this class is specified in the DJDoc configuration.


Constructor Summary
UserStrategy()
           
 
Method Summary
abstract  User authenticate(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
          This method authenticates the user.
protected static User findUserInDatabase(java.lang.String userName)
          This method attempts to look up a user in the database by his/her name.
static UserStrategy getStrategy()
          This method returns the single instance of the UserStrategy class.
protected static java.lang.String retrieveUserNameFromCookie(javax.servlet.http.HttpServletRequest req)
          This utility method is used in the SimpleUserStrategy class; it extracts a username string from a browser cookie sent in the request.
static void setup(java.lang.String strategyClassName)
          This static method initializes the (single) instance of the UserStrategy via reflection.
protected static void storeUserNameInCookie(java.lang.String userName, javax.servlet.http.HttpServletResponse res)
          This method is used to store a (newly created) user name in a browser cookie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserStrategy

public UserStrategy()
Method Detail

setup

public static void setup(java.lang.String strategyClassName)
                  throws ConfigurationException
This static method initializes the (single) instance of the UserStrategy via reflection.

Parameters:
strategyClassName - The name of the concrete class implementing the UserStrategy
Throws:
ConfigurationException - A ConfigurationException is thrown if an invalid class name is specified or if the construction of an instance of the specified class fails.

getStrategy

public static UserStrategy getStrategy()
This method returns the single instance of the UserStrategy class.

Returns:
The instance of the UserStrategy class.

authenticate

public abstract User authenticate(javax.servlet.http.HttpServletRequest httpServletRequest,
                                  javax.servlet.http.HttpServletResponse httpServletResponse)
This method authenticates the user. It needs to be implemented by all concrete subclasses of the UserStrategy class. The method is not responsible for authorization.

Parameters:
httpServletRequest - The current HTTP request object
httpServletResponse - The current HTTP response object
Returns:
An existing (or a new) User object

retrieveUserNameFromCookie

protected static java.lang.String retrieveUserNameFromCookie(javax.servlet.http.HttpServletRequest req)
This utility method is used in the SimpleUserStrategy class; it extracts a username string from a browser cookie sent in the request.

Parameters:
req - The current HTTP request object
Returns:
A user name sent as a session cookie (identified by the key DJDOC_USER); null if no such cookie is set.

storeUserNameInCookie

protected static void storeUserNameInCookie(java.lang.String userName,
                                            javax.servlet.http.HttpServletResponse res)
This method is used to store a (newly created) user name in a browser cookie. Like the method retrieveUserNameFromCookie(HttpServletRequest), it is used by the SimpleUserStrategy. It is identified by the key DJDOC_USER and has a duration of one week.

Parameters:
userName - The user name to be stored in the cookie
res - The HTTP response object to which the cookie is written

findUserInDatabase

protected static User findUserInDatabase(java.lang.String userName)
This method attempts to look up a user in the database by his/her name. If a user of that name does not exist in the database, a new one is created and stored in the database.

Parameters:
userName - The name of the user to be looked up
Returns:
An (existing or new) User with the specified name

DJDoc v.1.0.0b-1