org.abstracthorizon.danube.http.session
Class SimpleCookieSessionManager

java.lang.Object
  extended by org.abstracthorizon.danube.http.session.SimpleCookieSessionManager
All Implemented Interfaces:
HTTPSessionManager, SessionManager
Direct Known Subclasses:
SimpleSessionManager

public class SimpleCookieSessionManager
extends Object
implements HTTPSessionManager

Simple session manager implementation that uses cookies for storing session id on the client side. Sessions are not expired.

Author:
Daniel Sendula

Field Summary
static int DEFAULT_SESSION_TIMEOUT
          Default session timeout as 30 minutes
protected static Random random
          Random number for creating session ids
static String SESSION_ATTRIBUTE
          Connection attribute name for session to be temporarely stored at
static String SESSION_COOKIE_NAME
          Default session cookie name
protected  String sessionCookieName
          Name of session cookie.
protected  Map<Object,Session> sessions
          Map of sessions
 
Constructor Summary
SimpleCookieSessionManager()
           
 
Method Summary
protected  Session createSession(String sessionId)
          Creates new session object with given session id
protected  String createSessionId()
          Creates session id
 Object findSession(HTTPConnection connection, boolean create)
          Finds a session for supplied connection
 Object findSession(Object sessionId, boolean create)
          Searches for the session using givne session id
 String getSessionCookieName()
          Returns session's cookie name
 void removeSession(HTTPConnection connection)
          Removes session from connection
 void removeSession(Object session)
          This object removes existing session
 String rewriteURL(HTTPConnection connection, String url)
          Rewrites URL for given connection
 void setSessionCookieName(String sessionCookieName)
          Sets session's cookie name
protected  String validateSessionId(String sessionId)
          Validates session id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_COOKIE_NAME

public static final String SESSION_COOKIE_NAME
Default session cookie name

See Also:
Constant Field Values

SESSION_ATTRIBUTE

public static final String SESSION_ATTRIBUTE
Connection attribute name for session to be temporarely stored at

See Also:
Constant Field Values

DEFAULT_SESSION_TIMEOUT

public static final int DEFAULT_SESSION_TIMEOUT
Default session timeout as 30 minutes

See Also:
Constant Field Values

sessions

protected Map<Object,Session> sessions
Map of sessions


sessionCookieName

protected String sessionCookieName
Name of session cookie. Defaulted to SESSION_COOKIE_NAME.


random

protected static Random random
Random number for creating session ids

Constructor Detail

SimpleCookieSessionManager

public SimpleCookieSessionManager()
Method Detail

findSession

public Object findSession(HTTPConnection connection,
                          boolean create)
Finds a session for supplied connection

Specified by:
findSession in interface HTTPSessionManager
Parameters:
connection - connection
create - flag defining should session be created it doesn't exist already
Returns:
existing session object, new session if existing session is not there and create param is set to true or null otherwise.

findSession

public Object findSession(Object sessionId,
                          boolean create)
Searches for the session using givne session id

Specified by:
findSession in interface SessionManager
Parameters:
sessionId - session id object
create - flag defining should session be created it doesn't exist already
Returns:
existing session object, new session if existing session is not there and create param is set to true or null otherwise.

removeSession

public void removeSession(HTTPConnection connection)
Removes session from connection

Specified by:
removeSession in interface HTTPSessionManager
Parameters:
connection - connection

removeSession

public void removeSession(Object session)
This object removes existing session

Specified by:
removeSession in interface SessionManager
Parameters:
session - session to be removed

rewriteURL

public String rewriteURL(HTTPConnection connection,
                         String url)
Rewrites URL for given connection

Specified by:
rewriteURL in interface HTTPSessionManager
Parameters:
url - URL to be rewritten
connection - http connection object
Returns:
updated url

validateSessionId

protected String validateSessionId(String sessionId)
Validates session id. This implementation does nothing

Parameters:
sessionId - session id
Returns:
session id

createSessionId

protected String createSessionId()
Creates session id

Returns:
new session id

createSession

protected Session createSession(String sessionId)
Creates new session object with given session id

Parameters:
sessionId - session id
Returns:
new session object

getSessionCookieName

public String getSessionCookieName()
Returns session's cookie name

Returns:
session's cookie name

setSessionCookieName

public void setSessionCookieName(String sessionCookieName)
Sets session's cookie name

Parameters:
sessionCookieName - session's cookie name


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.