Interface SessionStore
- All Known Implementing Classes:
InMemorySessionStore
Sessions keep session data, keyed by the secret session identifier.
Contract. Implementations are thread-safe, enforce the idle and absolute timeouts and a
bound on the number of sessions themselves, and never return or accept an expired session.
Identifiers are 43-character base64url secrets chosen by Sessions; a store treats them as
credentials: it must not log them, and should key its storage by a digest of the identifier so a
leaked dump or log of keys cannot be replayed. Methods may block on I/O; they run on the
request's virtual thread.
Atomicity. update(java.lang.String, java.util.function.UnaryOperator<com.jsgalactic.axiom.security.SessionState>) and rename(java.lang.String, java.lang.String) are atomic with respect to every other
operation on the same identifier, so concurrent requests of one session do not lose each other's
attribute changes. A distributed store implements update with a compare-and-set loop,
which is why the function must be pure and may run more than once.
Timestamps. The store stamps createdAt when a session is created (ignoring the
state's) and lastAccessedAt on every successful find(java.lang.String), update(java.lang.String, java.util.function.UnaryOperator<com.jsgalactic.axiom.security.SessionState>) and rename(java.lang.String, java.lang.String). Renaming keeps createdAt: rotating the identifier does not extend the absolute
lifetime.
-
Method Summary
Modifier and TypeMethodDescriptionbooleancreate(String id, SessionState state) Stores a new session.Returns a live session and counts the call as an access (the idle timeout restarts).voidDeletes a session; unknown identifiers are ignored.booleanAtomically gives a live session a new identifier; the old one stops working at once.booleanupdate(String id, UnaryOperator<SessionState> change) Atomically replaces a live session's state with the function's result.
-
Method Details
-
create
Stores a new session.- Parameters:
id- the identifierstate- the initial state- Returns:
- false if the identifier is already in use (the caller picks another)
-
find
Returns a live session and counts the call as an access (the idle timeout restarts).- Parameters:
id- the identifier- Returns:
- the state with the new access time, or empty when unknown or expired
-
update
Atomically replaces a live session's state with the function's result.- Parameters:
id- the identifierchange- a pure function from the current state to the new one; may be called repeatedly- Returns:
- false when the session is unknown or expired, in which case nothing changed
-
rename
Atomically gives a live session a new identifier; the old one stops working at once.- Parameters:
id- the current identifiernewId- the new identifier- Returns:
- false when the session is unknown or expired, or the new identifier is in use
-
remove
Deletes a session; unknown identifiers are ignored.- Parameters:
id- the identifier
-