Package kz.greetgo.security.session
Interface SessionService
- All Superinterfaces:
java.lang.AutoCloseable
public interface SessionService
extends java.lang.AutoCloseable
Generates, caches, stores, give access and removes sessions
-
Method Summary
Modifier and Type Method Description voidclose()Закрывает различные ресурсы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 sessionvoididle()This method must be called every 5 seconds to do pending operationsvoidremoveOldSessions(int hoursOld)Removes all sessions with age is too big.voidremoveSession(java.lang.String sessionId)Removes session from cache and from storagebooleanverifyId(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 identity
-
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
-
removeSession
void removeSession(java.lang.String sessionId)Removes session from cache and from storage- Parameters:
sessionId- removing session id
-
removeOldSessions
void removeOldSessions(int hoursOld)Removes all sessions with age is too big.- Parameters:
hoursOld- number of hours of age to delete sessions
-
idle
void idle()This method must be called every 5 seconds to do pending operations -
close
void close()Закрывает различные ресурсы- Specified by:
closein interfacejava.lang.AutoCloseable
-