Package ch.tocco.nice2.userbase.impl
Class SessionManagerImpl
java.lang.Object
ch.tocco.nice2.userbase.impl.SessionManagerImpl
- All Implemented Interfaces:
SessionManager
-
Field Summary
Fields inherited from interface ch.tocco.nice2.userbase.api.SessionManager
SESSION_TIME_OUT_MILLISECONDS, SESSION_TIME_OUT_MINUTES
-
Constructor Summary
ConstructorDescriptionSessionManagerImpl
(org.slf4j.Logger log, PrincipalService principalService, CommandExecutor executor, QueryBuilderFactory queryBuilderFactory) -
Method Summary
Modifier and TypeMethodDescriptioncreateSession
(String username, ApiKey apiKey, String ipAddress, @Nullable String userAgent) createSession
(String username, String ipAddress, @Nullable String userAgent) Creates a new session for the existing principal.void
deleteAllSessions
(String username, boolean includingCurrent) Deletes all available sessions of specified principal.void
deleteExpiredSessions
(long timeoutMillis) Removes at mostamount
sessions that are older than the specified time out.void
deleteSession
(UUID uuid) Deletes the session with the specified uuid.getSession
(UUID uuid, long timeoutMillis, @Nullable String userAgent, @Nullable ApiKey apiKey) Finds the session with the specified uuid, which is not older than the specified timeout (= session.time>=
(now-timeout)) and has the same user agent.boolean
isSessionActive
(UUID uuid, long timeoutMillis)
-
Constructor Details
-
SessionManagerImpl
public SessionManagerImpl(org.slf4j.Logger log, PrincipalService principalService, CommandExecutor executor, QueryBuilderFactory queryBuilderFactory)
-
-
Method Details
-
deleteExpiredSessions
Description copied from interface:SessionManager
Removes at mostamount
sessions that are older than the specified time out.- Specified by:
deleteExpiredSessions
in interfaceSessionManager
- Parameters:
timeoutMillis
- timeout to find sessions older than this- Throws:
SessionDataException
-
getSession
public Optional<Session> getSession(UUID uuid, long timeoutMillis, @Nullable @Nullable String userAgent, @Nullable @Nullable ApiKey apiKey) throws SessionDataException Description copied from interface:SessionManager
Finds the session with the specified uuid, which is not older than the specified timeout (= session.time>=
(now-timeout)) and has the same user agent. Session time is updated automatically.- Specified by:
getSession
in interfaceSessionManager
- Parameters:
uuid
- the id of the session.timeoutMillis
- the timeout interval in milliseconds. Session is only returned if it is not older than the current time minus this timeout.userAgent
- the user agent whuch must match.- Returns:
- the session or
Optional.empty()
. - Throws:
SessionDataException
-
isSessionActive
- Specified by:
isSessionActive
in interfaceSessionManager
- Returns:
- true if there is an active session with the given uuid
-
createSession
public Session createSession(String username, String ipAddress, @Nullable @Nullable String userAgent) throws SessionDataException Description copied from interface:SessionManager
Creates a new session for the existing principal.- Specified by:
createSession
in interfaceSessionManager
- Parameters:
username
- the current user's usernameipAddress
- the ip address of the clientuserAgent
- the user agent of the client- Returns:
- the created session
- Throws:
SessionDataException
-
createSession
public Session createSession(String username, ApiKey apiKey, String ipAddress, @Nullable @Nullable String userAgent) throws SessionDataException Description copied from interface:SessionManager
- Specified by:
createSession
in interfaceSessionManager
- Throws:
SessionDataException
-
deleteSession
Description copied from interface:SessionManager
Deletes the session with the specified uuid.- Specified by:
deleteSession
in interfaceSessionManager
- Parameters:
uuid
- the id of the session.
-
deleteAllSessions
Description copied from interface:SessionManager
Deletes all available sessions of specified principal.- Specified by:
deleteAllSessions
in interfaceSessionManager
- Parameters:
username
- of principalincludingCurrent
- when set to true, also set currently used session which will lead to an invalid current session.
-