Class InMemorySessionStore
- All Implemented Interfaces:
SessionStore
SessionStore backed by a bounded-LRU map, indexed by sub and sid so
it can satisfy back-channel logout.
This is the simpler single-instance / development option. It is lost on restart and breaks under
horizontal scaling without sticky sessions; for production multi-instance deployments use
SignedCookieSessionStore (stateless, the documented default) or a caller-supplied distributed
store.
Eviction is the conjunction of a size cap (LRU) and per-session TTL (an expired session is treated as
a miss and removed on lookup). Because it retains sessions server-side, it
supports invalidateBySubject(String) and
invalidateBySessionId(String).
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of live sessions retained. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InMemorySessionStorecreate()Static creator with the default size cap.static InMemorySessionStorecreate(int maxEntries) Static creator with a custom size cap.createSessionCookieValue(OidcSession session) Persists the supplied session and returns the opaque value to set as the session cookie.voidinvalidate(String cookieValue) Invalidates the session identified by the supplied cookie value.intInvalidates the session(s) bound to the supplied IdP session id (sid).intinvalidateBySubject(String subject) Invalidates every session belonging to the supplied subject (sub).Resolves a session from a cookie value.intsize()Returns the current live-session count.booleanReturns whether this store can revoke sessions server-side (a prerequisite for back-channel logout).
-
Field Details
-
DEFAULT_MAX_ENTRIES
Default maximum number of live sessions retained.- See Also:
-
-
Constructor Details
-
InMemorySessionStore
Constructor.- Parameters:
maxEntries- The maximum number of live sessions. Must be positive.clock- The clock used for TTL comparisons. Must not benull .
-
-
Method Details
-
create
Static creator with the default size cap.- Returns:
- A new store.
-
create
Static creator with a custom size cap.- Parameters:
maxEntries- The maximum number of live sessions. Must be positive.- Returns:
- A new store.
-
createSessionCookieValue
Description copied from interface:SessionStorePersists the supplied session and returns the opaque value to set as the session cookie.For a server-side store this is typically a random session id used as a lookup key; for a stateless cookie store it is the entire signed session payload.
- Specified by:
createSessionCookieValuein interfaceSessionStore- Parameters:
session- The session to persist. Must not benull .- Returns:
- The cookie value the client should send back on subsequent requests. Never
null .
-
lookup
Description copied from interface:SessionStoreResolves a session from a cookie value.- Specified by:
lookupin interfaceSessionStore- Parameters:
cookieValue- The cookie value previously returned bySessionStore.createSessionCookieValue(org.apache.juneau.rest.server.auth.oidc.rp.OidcSession). Must not benull .- Returns:
- The resolved session, or
Optional.empty()if absent, expired, invalid, or tampered.
-
invalidate
Description copied from interface:SessionStoreInvalidates the session identified by the supplied cookie value. No-op if absent.- Specified by:
invalidatein interfaceSessionStore- Parameters:
cookieValue- The cookie value. Must not benull .
-
supportsServerSideRevocation
Description copied from interface:SessionStoreReturns whether this store can revoke sessions server-side (a prerequisite for back-channel logout).Defaults to
false — stateless cookie stores cannot revoke a session the server never retained.- Specified by:
supportsServerSideRevocationin interfaceSessionStore- Returns:
true ifSessionStore.invalidateBySubject(String)/SessionStore.invalidateBySessionId(String)are supported.
-
invalidateBySubject
Description copied from interface:SessionStoreInvalidates every session belonging to the supplied subject (sub).Used by
OidcRelyingParty.backChannelLogout(java.lang.String)when the IdP-pushed logout token carries asubbut nosid.- Specified by:
invalidateBySubjectin interfaceSessionStore- Parameters:
subject- The subject identifier. Must not benull or blank.- Returns:
- The number of sessions invalidated.
-
invalidateBySessionId
Description copied from interface:SessionStoreInvalidates the session(s) bound to the supplied IdP session id (sid).Used by
OidcRelyingParty.backChannelLogout(java.lang.String)when the IdP-pushed logout token carries asid.- Specified by:
invalidateBySessionIdin interfaceSessionStore- Parameters:
sid- The IdP session id. Must not benull or blank.- Returns:
- The number of sessions invalidated.
-
size
Returns the current live-session count. Primarily for tests and metrics.- Returns:
- The session count.
-