Package kz.greetgo.security.session
Interface SessionService
public interface SessionService
Generates, caches, stores, give access and removes sessions
-
Method Summary
Modifier and Type Method Description SessionIdentitycreateSession(java.lang.Object sessionData)Creates new session in storage with specified sessionData<T> TgetSessionData(java.lang.String sessionId)Gives session data by session idjava.util.Optional<java.lang.String>getToken(java.lang.String sessionId)Loads token for specified sessionvoidremoveOldSessions()Removes all sessions with age is too big.voidremoveSession(java.lang.String sessionId)Removes session from cache and from storagejava.util.Map<java.lang.String,java.lang.String>statisticsInfo()Retrieves statistics informationvoidsyncCache()Synchronizes cache with storage: for each session in cache it verify session state in storage and modify or remove sessionbooleanverifyId(java.lang.String sessionId)Verifies session id salt.booleanverifyToken(java.lang.String sessionId, java.lang.String token)Verify token: loads token from storage ot cache and check its identityvoidzeroSessionAge(java.lang.String sessionId)Makes session age to zero (in storage or in cache)
-
Method Details
-
createSession
Creates new session in storage with specified sessionData- Parameters:
sessionData- additional session data to store in session (it can contain userId, role or else)- Returns:
- session identity witch contains session id and token. Session id contains salt that nobody cannot create it
-
getSessionData
<T> T getSessionData(java.lang.String sessionId)Gives session data by session id- Parameters:
sessionId- session id- Returns:
- session data or null if session with specified id is absent
-
verifyId
boolean verifyId(java.lang.String sessionId)Verifies session id salt. Very quick operation- Parameters:
sessionId- session id- Returns:
- verification result: true - session id salt is good, false - otherwise
-
verifyToken
boolean verifyToken(java.lang.String sessionId, java.lang.String token)Verify token: loads token from storage ot cache and check its identity- Parameters:
sessionId- session idtoken- verifying token- Returns:
- verification result: true - tokens are same to each other, false - tokens are not same
-
getToken
java.util.Optional<java.lang.String> getToken(java.lang.String sessionId)Loads token for specified session- Parameters:
sessionId- specified session id- Returns:
- token
-
zeroSessionAge
void zeroSessionAge(java.lang.String sessionId)Makes session age to zero (in storage or in cache)- Parameters:
sessionId- id of age zeroing session
-
removeSession
void removeSession(java.lang.String sessionId)Removes session from cache and from storage- Parameters:
sessionId- removing session id
-
removeOldSessions
void removeOldSessions()Removes all sessions with age is too big. Maximum age defined inSessionServiceBuilder -
syncCache
void syncCache()Synchronizes cache with storage: for each session in cache it verify session state in storage and modify or remove session -
statisticsInfo
java.util.Map<java.lang.String,java.lang.String> statisticsInfo()Retrieves statistics information- Returns:
- statistics information in map
-