WPI GDC CMS 0.0.1

org.wpi.gdc.cms.main
Class Session

java.lang.Object
  |
  +--org.wpi.gdc.cms.main.Session
All Implemented Interfaces:
org.apache.avalon.framework.logger.Loggable

public class Session
extends java.lang.Object
implements org.apache.avalon.framework.logger.Loggable

This class represents the current CMS session. Sessions are basically separate instances of a CMS, allowing multiple CMS to be run in one Java Virtual Machine. Sessions are created via a String that should be specified via the given page/servlet's configuration. The CMS system then either returns the already existing Session based on that Core object or instead loads the Session.

Version:
1.7
Author:
dmpotter

Field Summary
protected  java.util.HashMap dataSources
          Data sources relating to this session.
protected  DBEngine engine
          The database engine used to load objects for this session.
protected  Icon[] icons
          Icons from the database (icons are loaded on session creation and are always available).
protected  Topic[] topics
          Topics from the database (topics are loaded on session creation and are always available).
protected  java.util.HashMap users
          Cache of user objects.
 
Method Summary
 boolean checkUserExists(int id)
          Returns false.
 boolean checkUserExists(User user)
          Returns false.
 User getAuthenticatedUser(java.lang.String hash)
          Loads the user associated with the authentication token or returns null if either the user does not exist or the authentication failed.
 java.lang.Class getDataSource(java.lang.String name)
          Gets the data source associated with the given string, or null if there is no source for the given name.
 DBEngine getDBEngine()
          Retrieves the database engine.
 Icon getIcon(int id)
          Get an icon based on the ID for the Icon.
protected  org.apache.log.Logger getLogger()
           
static Session getSession(java.lang.String sessionID)
          Obtains a session based on the session ID.
 Topic getTopic(int id)
          Get a topic based on the ID for the Topic.
 Topic[] getTopics()
          Retreives all the topic items.
 User getUser(int id)
          Gets a user based on the given ID - returns null if the user doesn't exist.
 User getUser(java.lang.String username)
          Gets a user based on the given username - returns null if the user doesn't exist.
 java.lang.String hashUser(User user)
          Creates an athentication token for a User object, used to reobtain the user of subsequent calls.
static void loadConfiguration(java.io.File confFile)
           
static void loadConfiguration(java.lang.String confFile)
          Loads a given configuration file.
 void setLogger(org.apache.log.Logger logger)
           
 User validateUser(java.lang.String username, java.lang.String password)
          Validates the username/password pair, returning the user if the username and password are valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engine

protected DBEngine engine
The database engine used to load objects for this session.

dataSources

protected java.util.HashMap dataSources
Data sources relating to this session.

users

protected java.util.HashMap users
Cache of user objects.

topics

protected Topic[] topics
Topics from the database (topics are loaded on session creation and are always available).

icons

protected Icon[] icons
Icons from the database (icons are loaded on session creation and are always available).
Method Detail

loadConfiguration

public static void loadConfiguration(java.lang.String confFile)
                              throws ConfigParseException,
                                     java.io.IOException
Loads a given configuration file.

loadConfiguration

public static void loadConfiguration(java.io.File confFile)
                              throws ConfigParseException,
                                     java.io.IOException

getSession

public static Session getSession(java.lang.String sessionID)
Obtains a session based on the session ID. If no configuration file has been loaded via loadConfiguration(java.io.File) then the default session will be returned. (The default session can also be accessed directly via the session ID "<DEFAULT>".)
Parameters:
sessionID - the session ID for the session to retrieve.
Returns:
the Session object for the given session ID.

checkUserExists

public boolean checkUserExists(User user)
Returns false. Checks to see if the given user account exists within this session.
Parameters:
user - the user account to check
Returns:
true if the user account belongs to this session, false if it does not

checkUserExists

public boolean checkUserExists(int id)
Returns false. Checks if the user account with the given ID exists.

getUser

public User getUser(int id)
             throws DatabaseException
Gets a user based on the given ID - returns null if the user doesn't exist.
Parameters:
id - the user ID
Returns:
the User or null if the user doesn't exist
Throws:
DatabaseException - if the user could not be loaded.

getUser

public User getUser(java.lang.String username)
             throws DatabaseException
Gets a user based on the given username - returns null if the user doesn't exist.
Parameters:
username - the user's username
Returns:
the User or null if the user doesn't exist
Throws:
DatabaseException - if the user could not be loaded.

getDataSource

public java.lang.Class getDataSource(java.lang.String name)
Gets the data source associated with the given string, or null if there is no source for the given name.

getDBEngine

public DBEngine getDBEngine()
Retrieves the database engine.
Returns:
The database engine.

hashUser

public java.lang.String hashUser(User user)
Creates an athentication token for a User object, used to reobtain the user of subsequent calls.

THIS IS NOT SECURE YET.

The athentication token is currently just the User ID.

Parameters:
user - The user to create a token for.
Returns:
The token to validate.
See Also:
getAuthenticatedUser(java.lang.String)

getAuthenticatedUser

public User getAuthenticatedUser(java.lang.String hash)
Loads the user associated with the authentication token or returns null if either the user does not exist or the authentication failed.

THIS IS NOT SECURE YET.

The athentication token is currently just the User ID.

Parameters:
hash - The authentication token.
Returns:
The user authenticated with the token, Null otherwise.
See Also:
hashUser(User)

validateUser

public User validateUser(java.lang.String username,
                         java.lang.String password)
Validates the username/password pair, returning the user if the username and password are valid.
Parameters:
username - The username.
password - The password.
Returns:
The user belonging to the username/password pair, or null if there is no user.

getIcon

public Icon getIcon(int id)
Get an icon based on the ID for the Icon.
Parameters:
id - the ID of the icon (the ID must be positive)
Returns:
the icon, or null if the icon is not found
Throws:
java.lang.IllegalArgumentException - if the id is less than 0

getTopic

public Topic getTopic(int id)
Get a topic based on the ID for the Topic.
Parameters:
id - the ID of the icon (the ID must be positive)
Returns:
the topic, or null if the topic is not found
Throws:
java.lang.IllegalArgumentException - if the id is less than 0

getTopics

public Topic[] getTopics()
Retreives all the topic items.
Returns:
All the topics.

getLogger

protected org.apache.log.Logger getLogger()

setLogger

public void setLogger(org.apache.log.Logger logger)
Specified by:
setLogger in interface org.apache.avalon.framework.logger.Loggable

WPI GDC CMS 0.0.1

Copyright © 2001 WPI Game Development Club. All Rights Reserved.