- All Known Implementing Classes:
SessionStore.InMemory
- Since:
- 2.0.0
- Author:
- edgar
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Base class for in-memory session store. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Default session timeout in minutes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteSession
(Context ctx, Session session) Delete a session from store.findSession
(Context ctx) Find an existing session by ID.static SessionStore
memory()
Creates a cookie based session and store data in memory.static SessionStore
memory
(int timeout) Creates a cookie based session and store data in memory.static SessionStore
Creates a cookie based session and store data in memory.static SessionStore
Creates a cookie based session and store data in memory.static SessionStore
memory
(SessionToken token) Creates a session store that save data in memory.static SessionStore
memory
(SessionToken token, Duration timeout) Creates a session store that save data in memory.static SessionStore
Creates a cookie based session and store data in memory.newSession
(Context ctx) Creates a new session.void
renewSessionId
(Context ctx, Session session) Renew Session ID.void
saveSession
(Context ctx, Session session) Save a session.static SessionStore
signed
(SessionToken token, Function<String, Map<String, String>> decoder, Function<Map<String, String>, String> encoder) Creates a session store that save data into Cookie.static SessionStore
Creates a session store that uses (un)signed data.static SessionStore
Creates a session store that uses (un)signed data.static SessionStore
signed
(String secret, SessionToken token) Creates a session store that uses (un)signed data.void
touchSession
(Context ctx, Session session) Session attributes/state has changed.
-
Field Details
-
DEFAULT_TIMEOUT
static final int DEFAULT_TIMEOUTDefault session timeout in minutes.- See Also:
-
-
Method Details
-
newSession
Creates a new session. This method must:- Set session as new
Session.setNew(boolean)
- Optionally, set session creation timeSession.setCreationTime(Instant)
- Optionally, set session last accessed timeSession.setLastAccessedTime(Instant)
- Parameters:
ctx
- Web context.- Returns:
- A new session.
-
findSession
Find an existing session by ID. For existing session this method must:- Optionally, Retrieve/restore session creation time - Optionally, Set session last accessed time
Session.setLastAccessedTime(Instant)
- Parameters:
ctx
- Web context.- Returns:
- An existing session or
null
.
-
deleteSession
Delete a session from store. This method must NOT callSession.destroy()
.- Parameters:
ctx
- Web context.session
- Current session.
-
touchSession
Session attributes/state has changed. Every time a session attribute is put or removed it, this method is executed as notification callback.- Parameters:
ctx
- Web context.session
- Current session.
-
saveSession
Save a session. This method must save:- Session attributes/data - Optionally set Session metadata like: creationTime, lastAccessed time, etc.
This method is call after response is send to client, so context and response shouldn't be modified.
- Parameters:
ctx
- Web context.session
- Current session.
-
renewSessionId
Renew Session ID. This operation might or might not be implemented by a Session Store.- Parameters:
ctx
- Web Context.session
- Session.
-
memory
Creates a cookie based session and store data in memory. Session data is not keep after restart.It uses the default session cookie:
SessionToken.SID
.- Session data is not keep after restart.
- Parameters:
timeout
- Timeout in seconds. Use-1
for no timeout.- Returns:
- Session store.
-
memory
Creates a cookie based session and store data in memory. Session data is not keep after restart.It uses the default session cookie:
SessionToken.SID
.- Session expires after 30 minutes of inactivity. - Session data is not keep after restart.
- Returns:
- Session store.
-
memory
Creates a cookie based session and store data in memory. Session data is not keep after restart.It uses the default session cookie:
SessionToken.SID
.- Parameters:
timeout
- Expires session after amount of inactivity time.- Returns:
- Session store.
-
memory
Creates a cookie based session and store data in memory.- Session expires after 30 minutes of inactivity. - Session data is not keep after restart.
- Parameters:
cookie
- Cookie to use.- Returns:
- Session store.
-
memory
Creates a cookie based session and store data in memory. Session data is not keep after restart.- Parameters:
cookie
- Cookie to use.timeout
- Expires session after amount of inactivity time.- Returns:
- Session store.
-
memory
Creates a session store that save data in memory. - Session expires after 30 minutes of inactivity. - Session data is not keep after restart.- Parameters:
token
- Session token.- Returns:
- Session store.
-
memory
Creates a session store that save data in memory. Session data is not keep after restart.- Parameters:
token
- Session token.timeout
- Expires session after amount of inactivity time.- Returns:
- Session store.
-
signed
Creates a session store that uses (un)signed data. Session data is signed it usingHMAC_SHA256
.See
Cookie.sign(String, String)
andCookie.unsign(String, String)
.- Parameters:
secret
- Secret token to signed data.- Returns:
- A browser session store.
-
signed
Creates a session store that uses (un)signed data. Session data is signed it usingHMAC_SHA256
.See
Cookie.sign(String, String)
andCookie.unsign(String, String)
.- Parameters:
secret
- Secret token to signed data.cookie
- Cookie to use.- Returns:
- A browser session store.
-
signed
Creates a session store that uses (un)signed data. Session data is signed it usingHMAC_SHA256
.See
Cookie.sign(String, String)
andCookie.unsign(String, String)
.- Parameters:
secret
- Secret token to signed data.token
- Session token to use.- Returns:
- A browser session store.
-
signed
@NonNull static SessionStore signed(@NonNull SessionToken token, @NonNull Function<String, Map<String, String>> decoder, @NonNull Function<Map<String, String>, String> encoder) Creates a session store that save data into Cookie. Cookie data is (un)signed it using the given decoder and encoder.- Parameters:
token
- Token to use.decoder
- Decoder to use.encoder
- Encoder to use.- Returns:
- Cookie session store.
-