Package ome.services.sessions
Interface SessionManager
-
- All Known Implementing Classes:
SessionManagerImpl
public interface SessionManagerResponsible for holding ontoSessioninstances for optimized login.SessionManagerimplementations should strive to be only in-memory representations of the database used as a performance optimization. When possible, all changes should be made to the database as quickly and as synchronously as possible.- Since:
- 3.0-Beta3
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classSessionManager.CreationRequestExtensible data object which can be passed to create* methods to stop the explosion of different methods.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intclose(java.lang.String uuid)If reference count for the session is less than 1, close the session.intcloseAll()Close all sessions with checking for the necessary reference counts.ome.model.meta.SessioncreateFromRequest(SessionManager.CreationRequest request)ome.model.meta.SharecreateShare(ome.system.Principal principal, boolean enabled, long timeToLive, java.lang.String eventType, java.lang.String description, long groupId)ome.model.meta.SessioncreateWithAgent(ome.system.Principal principal, java.lang.String agent, java.lang.String ip)ome.model.meta.SessioncreateWithAgent(ome.system.Principal principal, java.lang.String credentials, java.lang.String agent, java.lang.String ip)intdetach(java.lang.String uuid)Allows decrementing the reference count for a session without calling the actualclose(String)logic.booleanexecutePasswordCheck(java.lang.String name, java.lang.String credentials)Executes a password check using theExecutorframework.ome.model.meta.Sessionfind(java.lang.String uuid)Finds aSessionand update the last access time.ome.model.meta.SessionfindQuietly(java.lang.String uuid)Finds aSessionwithout updating the last access time.java.util.List<ome.model.meta.Session>findSameUser(java.lang.String uuid, java.lang.String... agent)Returns a non-null, possibly empty list of session instances belonging to the same user as the given session with one of the given agents.ome.system.EventContextgetEventContext(ome.system.Principal principal)Provides a partialEventContextfor the currentSession.java.lang.ObjectgetInput(java.lang.String session, java.lang.String key)Returns the input environmentObjectstored under the given key or null if none present.java.lang.ObjectgetOutput(java.lang.String session, java.lang.String key)Returns the output environmentObjectstored under the given key or null if none present.intgetReferenceCount(java.lang.String uuid)Return the number of client which are presumed to be attached to this session or throw an exception if there's no such session.java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>getSessionData()Return all sessions that are active with associated possibly varying session data information.SessionStatsgetSessionStats(java.lang.String uuid)Return theSessionStatswhich are being counted for the given session or throw an exception if it has been removed.java.util.List<java.lang.String>getUserRoles(java.lang.String uuid)net.sf.ehcache.EhcacheinMemoryCache(java.lang.String uuid)Returns after possibly creating an in-memorycachewhich can be used throughout the session.java.util.Map<java.lang.String,java.lang.Object>inputEnvironment(java.lang.String session)Returns a copy of the input environment.net.sf.ehcache.EhcacheonDiskCache(java.lang.String uuid)Returns after possibly creating an on-diskcachewhich can be used throughout the session.java.util.Map<java.lang.String,java.lang.Object>outputEnvironment(java.lang.String session)Returns a copy of the output environment.ome.system.EventContextreload(java.lang.String uuid)Similar togetEventContext(Principal)but uses the internal reload logic to get a fresh representation of the context.voidsetInput(java.lang.String session, java.lang.String key, java.lang.Object object)Places theargumentin the input environment under the given key, possibly initializing theMapThrows an exception if there is noSessionwith the given identifier.voidsetOutput(java.lang.String session, java.lang.String key, java.lang.Object object)Places theargumentin the output environment under the given key, possibly initializing theMapThrows an exception if there is noSessionwith the given identifier.ome.model.IObjectsetSecurityContext(ome.system.Principal principal, ome.model.IObject obj)Sets the context for the current session to the given value.ome.model.meta.Sessionupdate(ome.model.meta.Session session)Certain fields from theSessioninstance will be copied and then saved to the db, as well as a newSessionContextcreated.ome.model.meta.Sessionupdate(ome.model.meta.Session session, boolean trust)Same asupdate(Session)but some security checks can be overridden.
-
-
-
Method Detail
-
createFromRequest
ome.model.meta.Session createFromRequest(SessionManager.CreationRequest request)
-
createWithAgent
ome.model.meta.Session createWithAgent(ome.system.Principal principal, java.lang.String credentials, java.lang.String agent, java.lang.String ip)- Parameters:
principal-credentials-agent-ip-- Returns:
- Not null. Instead an exception will be thrown.
-
createWithAgent
ome.model.meta.Session createWithAgent(ome.system.Principal principal, java.lang.String agent, java.lang.String ip)- Parameters:
principal-agent-ip-- Returns:
- Not null. Instead an exception will be thrown.
-
createShare
ome.model.meta.Share createShare(ome.system.Principal principal, boolean enabled, long timeToLive, java.lang.String eventType, java.lang.String description, long groupId)- Parameters:
principal-enabled-timeToLive-eventType-description-groupId-- Returns:
- Not null. Instead an exception will be thrown.
-
setSecurityContext
ome.model.IObject setSecurityContext(ome.system.Principal principal, ome.model.IObject obj)Sets the context for the current session to the given value. If it is anExperimenterGroupthen the active group is changed, and any active shares are deactivated. If it is anSharethen the share is activate (the group is left alone). Unless otherwise specified, the user's default group is used as the initial context. Passing any other object will result in anApiUsageException.- Parameters:
principal-Principalfor which the context should be set.obj-IObjectwhich represents the new context.- Returns:
- See above.
-
update
ome.model.meta.Session update(ome.model.meta.Session session)
Certain fields from theSessioninstance will be copied and then saved to the db, as well as a newSessionContextcreated. This method assumes that the user is NOT an admin.
-
update
ome.model.meta.Session update(ome.model.meta.Session session, boolean trust)Same asupdate(Session)but some security checks can be overridden. This is usually done by checking with theSecuritySystembut here the server is in a critical state, and instead will trust the method invoker.
-
detach
int detach(java.lang.String uuid)
Allows decrementing the reference count for a session without calling the actualclose(String)logic. This is useful when it is assumed that another user will re-attach to the same session. A timeout can still cause the session to be removed.- Parameters:
uuid-- Returns:
- See above.
-
getReferenceCount
int getReferenceCount(java.lang.String uuid)
Return the number of client which are presumed to be attached to this session or throw an exception if there's no such session.
-
getSessionStats
SessionStats getSessionStats(java.lang.String uuid)
Return theSessionStatswhich are being counted for the given session or throw an exception if it has been removed.
-
find
ome.model.meta.Session find(java.lang.String uuid)
Finds aSessionand update the last access time.- Parameters:
uuid-- Returns:
- A current session.
- Throws:
ome.conditions.SessionTimeoutException- if the session has timed out during this call. It will then be removed and subsequent calls will throw aRemovedSessionExceptionome.conditions.RemovedSessionException- if a previous call already excised this session
-
findQuietly
ome.model.meta.Session findQuietly(java.lang.String uuid)
Finds aSessionwithout updating the last access time.- Parameters:
uuid-- Returns:
- A current session.
- Throws:
ome.conditions.SessionTimeoutException- if the session has timed out during this call. It will then be removed and subsequent calls will throw aRemovedSessionExceptionome.conditions.RemovedSessionException- if a previous call already excised this session
-
findSameUser
java.util.List<ome.model.meta.Session> findSameUser(java.lang.String uuid, java.lang.String... agent)Returns a non-null, possibly empty list of session instances belonging to the same user as the given session with one of the given agents. Sudo is taken into account. If the agent list is empty then all are included. Anullmay be included in the list to include null agents.
-
getSessionData
java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> getSessionData()
Return all sessions that are active with associated possibly varying session data information.
-
close
int close(java.lang.String uuid)
If reference count for the session is less than 1, close the session. Otherwise decrement the reference count. The current reference count is returned. If -1, then no such session existed. If -2, then the session was removed.
-
closeAll
int closeAll()
Close all sessions with checking for the necessary reference counts.
-
getEventContext
ome.system.EventContext getEventContext(ome.system.Principal principal) throws ome.conditions.RemovedSessionExceptionProvides a partialEventContextfor the currentSession.- Parameters:
principal- Non null.- Returns:
- Never null.
- Throws:
ome.conditions.RemovedSessionException- if no session with the givenPrincipal.getName()
-
reload
ome.system.EventContext reload(java.lang.String uuid) throws ome.conditions.RemovedSessionExceptionSimilar togetEventContext(Principal)but uses the internal reload logic to get a fresh representation of the context. This queries all of the user management tables (experimenter, experimentergroup, etc) and so should not be used anywhere in a critical path.- Parameters:
uuid- non null.- Returns:
- See above.
- Throws:
ome.conditions.RemovedSessionException- If the uuid does not exist.
-
getUserRoles
java.util.List<java.lang.String> getUserRoles(java.lang.String uuid)
-
executePasswordCheck
boolean executePasswordCheck(java.lang.String name, java.lang.String credentials)Executes a password check using theExecutorframework. Also checks the credentials against current session uuids.- Parameters:
name-credentials-- Returns:
- See above.
-
inMemoryCache
net.sf.ehcache.Ehcache inMemoryCache(java.lang.String uuid)
Returns after possibly creating an in-memorycachewhich can be used throughout the session. On close, the cache will be disposed.
-
onDiskCache
net.sf.ehcache.Ehcache onDiskCache(java.lang.String uuid)
Returns after possibly creating an on-diskcachewhich can be used throughout the session. On close, the cache will be disposed.
-
getInput
java.lang.Object getInput(java.lang.String session, java.lang.String key) throws ome.conditions.RemovedSessionExceptionReturns the input environmentObjectstored under the given key or null if none present. Throws an exception if there is noSessionwith the given identifier.- Parameters:
session- Not null.key- Not null.- Returns:
- Possibly null.
- Throws:
ome.conditions.RemovedSessionException
-
getOutput
java.lang.Object getOutput(java.lang.String session, java.lang.String key) throws ome.conditions.RemovedSessionExceptionReturns the output environmentObjectstored under the given key or null if none present. Throws an exception if there is noSessionwith the given identifier.- Parameters:
session- Not null.key- Not null.- Returns:
- Possibly null.
- Throws:
ome.conditions.RemovedSessionException
-
setInput
void setInput(java.lang.String session, java.lang.String key, java.lang.Object object) throws ome.conditions.RemovedSessionExceptionPlaces theargumentin the input environment under the given key, possibly initializing theMapThrows an exception if there is noSessionwith the given identifier.- Parameters:
session- Not null.key- Not null.object- If null, key will be removed.- Throws:
ome.conditions.RemovedSessionException
-
setOutput
void setOutput(java.lang.String session, java.lang.String key, java.lang.Object object) throws ome.conditions.RemovedSessionExceptionPlaces theargumentin the output environment under the given key, possibly initializing theMapThrows an exception if there is noSessionwith the given identifier.- Parameters:
session- Not null.key- Not null.object- If null, key will be removed.- Throws:
ome.conditions.RemovedSessionException
-
inputEnvironment
java.util.Map<java.lang.String,java.lang.Object> inputEnvironment(java.lang.String session)
Returns a copy of the input environment.- Parameters:
session- The session id.- Returns:
- Not null
-
outputEnvironment
java.util.Map<java.lang.String,java.lang.Object> outputEnvironment(java.lang.String session)
Returns a copy of the output environment.- Parameters:
session- The session id.- Returns:
- Not null.
-
-