org.web_auth.bizobj.impl
Class UserSession

java.lang.Object
  extended byorg.web_auth.bizobj.impl.UserSession
All Implemented Interfaces:
IUserSession

public abstract class UserSession
extends java.lang.Object
implements IUserSession

An abstract class to model any type of user sessions. A user session is created after a user successful logs in. The user session then stores the user object in the session. The user object can be retrieved at any time before the session is expired or the user logs out.

Version:
1.0
Author:
Zhengrong Tang

Constructor Summary
UserSession()
           
 
Method Summary
 boolean createSession(java.sql.Connection conn, java.lang.String username)
          Creates a user session.
 java.lang.String getId()
           
abstract  int getSessionType()
          Subclass needs to implement this method to return a unique int that represents the type of user session.
 IUser getUser(javax.servlet.http.HttpServletRequest request)
          Get the IUser object from the current session
 void invalidateSession(java.sql.Connection conn)
          Makes this user session invalid.
static void InvalidateSession(java.sql.Connection conn, java.lang.String sessId)
          Makes a user session invalid.
 boolean isLoggedIn(java.sql.Connection conn, javax.servlet.http.HttpServletRequest request)
          Checked whether a user has logged in or not based on whether the current HTTP session is a valid or not.
 boolean isValidSession(java.sql.Connection conn)
          Check whether the session object is a valid session or not.
 void setId(java.lang.String val)
           
 void setUser(javax.servlet.http.HttpServletRequest request, IUser user)
          Set the User object to the current session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserSession

public UserSession()
Method Detail

getId

public java.lang.String getId()
Specified by:
getId in interface IUserSession

setId

public void setId(java.lang.String val)
Specified by:
setId in interface IUserSession

getSessionType

public abstract int getSessionType()
Subclass needs to implement this method to return a unique int that represents the type of user session. For example, 1 means member session, 2 means admin session, etc.

Returns:
an int that indicates the type of the user session

getUser

public IUser getUser(javax.servlet.http.HttpServletRequest request)
Get the IUser object from the current session

Specified by:
getUser in interface IUserSession
Parameters:
request - The HttpSevletRequest object that links to the current session
Returns:
An IUser object.

setUser

public void setUser(javax.servlet.http.HttpServletRequest request,
                    IUser user)
Set the User object to the current session.

Specified by:
setUser in interface IUserSession
Parameters:
request - The HttpSevletRequest object that links to the current session
user - the IUser object to be set

isValidSession

public boolean isValidSession(java.sql.Connection conn)
Check whether the session object is a valid session or not.

Specified by:
isValidSession in interface IUserSession
Parameters:
conn - the database connection object for connecting to the database
Returns:
true if the session is valid, false otherwise

createSession

public boolean createSession(java.sql.Connection conn,
                             java.lang.String username)
Creates a user session.

Specified by:
createSession in interface IUserSession
Parameters:
conn - the database connection object for connecting to the database
username - the username associated to this session.
Returns:
true if the creation is successful; false otherwise

InvalidateSession

public static void InvalidateSession(java.sql.Connection conn,
                                     java.lang.String sessId)
Makes a user session invalid.

Parameters:
conn - the database connection object for connecting to the database
sessId - the id of the session to be invalidated

invalidateSession

public void invalidateSession(java.sql.Connection conn)
Makes this user session invalid.

Specified by:
invalidateSession in interface IUserSession
Parameters:
conn - the database connection object for connecting to the database

isLoggedIn

public boolean isLoggedIn(java.sql.Connection conn,
                          javax.servlet.http.HttpServletRequest request)
Checked whether a user has logged in or not based on whether the current HTTP session is a valid or not.

Specified by:
isLoggedIn in interface IUserSession
Parameters:
conn - the database connection object for connecting to the database
request - an HttpServletRequest
Returns:
true if a user is logged in; false otherwise


Copyright © 2003 Zhengrong Tang. All Rights Reserved.