Package net.sf.basedb.core
Class Session
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.Session
- All Implemented Interfaces:
AccessControlled
,Identifiable
public class Session extends BasicItem
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Session.QueryRuntimeFilterImpl
A runtime filter implementation that limits a query to only return sessions for the currently logged in user unless the logged in user has generic read permission. -
Field Summary
Fields Modifier and Type Field Description private static QueryRuntimeFilter
RUNTIME_FILTER
This filter will limit a query to only return sessions for the logged in user unless the logged in user has generic read permission.static Item
TYPE
The type of item represented by this class. -
Constructor Summary
Constructors Constructor Description Session(SessionData sessionData)
-
Method Summary
Modifier and Type Method Description (package private) static int
autoLogout()
Cleanup method that sets a logout-time on all sessions that doesn't have a logout time.String
getAuthenticationMethod()
Get the authentication method that was used to login to this session.static Session
getById(DbControl dc, int id)
Get aSession
item when you know the ID.Client
getClient()
Get the client application the user was using in this session.(package private) SessionData
getData()
Get theBasicData
object that holds all data for this item.UserDevice
getDevice()
Get the device the user was using in this session.boolean
getImpersonated()
Check if another user was acting as the user of this session.String
getLocation()
Get the location of the host the user used for this session.Float
getLocationLatitude()
Get the location latitude of the host the user used for this session.Float
getLocationLongitude()
Get the location longitude of the host the user used for 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
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, validate
-
Field Details
-
TYPE
The type of item represented by this class.- See Also:
Item.SESSION
,getType()
-
RUNTIME_FILTER
This filter will limit a query to only return sessions for the logged in user unless the logged in user has generic read permission.
-
-
Constructor Details
-
Session
Session(SessionData sessionData)
-
-
Method Details
-
getById
public static Session getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseExceptionGet aSession
item when you know the ID.- Parameters:
dc
- TheDbControl
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 foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemBaseException
- If there is another error
-
getQuery
Get a query configured to retrieve sessions for the specified user.- Parameters:
user
- The user to retreive sessions for or null to load all sessions.- Returns:
- An
ItemQuery
object
-
autoLogout
static int autoLogout()Cleanup method that sets a logout-time on all sessions that doesn't have a logout time.- Returns:
- The number of sessions updated
- Since:
- 3.18
-
getData
SessionData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this 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 theItem
enumeration.- Returns:
- A value indicating the type of item
-
initPermissions
READ permission is granted if the logged in user is the owner of this session. All other permissions are denied.- Overrides:
initPermissions
in classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass- Throws:
BaseException
- If the permissions couldn't be initialised
-
getUser
Get the user that logged in with this session.- Returns:
- The
User
item - Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permissionBaseException
- If there is another error
-
getClient
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 havePermission.READ
permissionBaseException
- If there is another error
-
getDevice
Get the device the user was using in this session.- Returns:
- A
UserDevice
item, or null if not known - Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permissionBaseException
- If there is another error- Since:
- 3.12
-
getLoginTime
Get the date and time the user logged in.- Returns:
- A
Date
object with the login time
-
getLogoutTime
Get the date and time the user logged out.- Returns:
- A
Date
object with the logout time
-
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
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
-
getLocation
Get the location of the host the user used for this session.- Returns:
- A
String
object with location or null if not known - Since:
- 3.12
-
getLocationLatitude
Get the location latitude of the host the user used for this session.- Returns:
- A
Float
object with latitude or null if not known - Since:
- 3.12
-
getLocationLongitude
Get the location longitude of the host the user used for this session.- Returns:
- A
Float
object with longitude or null if not known - Since:
- 3.12
-
getAuthenticationMethod
Get the authentication method that was used to login to this session.- Since:
- 3.9
-