2.17.2: 2011-06-17

net.sf.basedb.core
Class Session

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<SessionData>
      extended by net.sf.basedb.core.Session
All Implemented Interfaces:
AccessControlled, Identifiable

public class Session
extends BasicItem<SessionData>

A session represents the time between login and logout for a single user. Hence, a session item is automatically created when a user logs in, and is automatically updated when the user logs out.

A session said to be active when the user is logged in.

Version:
2.0
Author:
Nicklas

Field Summary
static Item TYPE
          The type of item represented by this class.
 
Constructor Summary
Session(SessionData sessionData)
           
 
Method Summary
static Session getById(DbControl dc, int id)
          Get a Session item when you know the ID.
 Client getClient()
          Get the client application the user was using in this session.
 boolean getImpersonated()
          Check if another user was acting as the user of this session.
 String getLoginComment()
          Get the login comment.
 Date getLoginTime()
          Get the date and time the user logged in.
 Date getLogoutTime()
          Get the date and time the user logged out.
static ItemQuery<Session> getQuery(User user)
          Get a query configured to retrieve sessions for the specified user.
 String getRemoteId()
          Get the remote ID of the host the user used for this session.
 Item getType()
          Get the type of item represented by the object.
 User getUser()
          Get the user that logged in with this session.
(package private)  void initPermissions(int granted, int denied)
          READ permission is granted if the logged in user is the owner of this session.
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.SESSION, getType()
Constructor Detail

Session

Session(SessionData sessionData)
Method Detail

getById

public static Session getById(DbControl dc,
                              int id)
                       throws ItemNotFoundException,
                              PermissionDeniedException,
                              BaseException
Get a Session item when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The ID of the item to load
Returns:
The Session item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getQuery

public static ItemQuery<Session> getQuery(User user)
Get a query configured to retrieve sessions for the specified user.

Parameters:
user - The user to retreive sessions for, null is allowed if the logged in user has generic READ permission for sessions in which case all sessions will be returned
Returns:
An ItemQuery object

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

initPermissions

void initPermissions(int granted,
                     int denied)
               throws BaseException
READ permission is granted if the logged in user is the owner of this session. All other permissions are denied.

Overrides:
initPermissions in class BasicItem<SessionData>
Parameters:
granted - Permissions that have been granted by the subclass
denied - Permissions that have been denied by the subclass
Throws:
BaseException - If the permissions couldn't be initialised

getUser

public User getUser()
             throws PermissionDeniedException,
                    BaseException
Get the user that logged in with this session.

Returns:
The User item
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission
BaseException - If there is another error

getClient

public Client getClient()
                 throws PermissionDeniedException,
                        BaseException
Get the client application the user was using in this session.

Returns:
A Client item, or null if not known
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission
BaseException - If there is another error

getLoginTime

public Date getLoginTime()
Get the date and time the user logged in.

Returns:
A Date object with the login time

getLogoutTime

public Date getLogoutTime()
Get the date and time the user logged out.

Returns:
A Date object with the logout time

getLoginComment

public String getLoginComment()
Get the login comment.

Returns:
A String object with the login comment

getImpersonated

public boolean getImpersonated()
Check if another user was acting as the user of this session.

Returns:
TRUE if the user was impersonated, FALSE otherwise

getRemoteId

public String getRemoteId()
Get the remote ID of the host the user used for this session. Typically it is the IP-address of the user's computer.

Returns:
A String object with remote ID

2.17.2: 2011-06-17