Interface SessionPolicy<U>
- Type Parameters:
U- the application's subject type
- All Known Implementing Classes:
NoopSessionPolicy, TimeoutSessionPolicy
The expected call sequence inside a Vaadin or REST adapter:
onLogin(SessionContext)— after a successful login. Implementations may emitSESSION_CREATEDaudit events and signal "rotate session id now" via the return value.beforeNavigation(SessionContext)— before each protected navigation (Vaadin: everyBeforeEnterEventon a restricted target; REST: every authenticated request). The returnedSessionDecisiondrives whether the navigation continues, requires re-authentication, or invalidates the session.onLogout(SessionContext)— when the subject explicitly logs out. Implementations may emitSESSION_INVALIDATEDaudit events.
The default implementation NoopSessionPolicy returns
SessionDecision.Continue.INSTANCE for every event. The provided
TimeoutSessionPolicy adds idle / absolute timeouts and
optional session-id rotation.
-
Method Summary
Modifier and TypeMethodDescriptionbeforeNavigation(SessionContext<U> context) Called before each protected navigation.default SessionPolicyDecisionevaluate(SessionMetadata metadata) Pure-query lifetime check used by the VaadinSessionLifetimeListenerand the REST authentication / authorization filters.default SessionDecisiononLogin(SessionContext<U> context) Called after a successful login.default voidonLogout(SessionContext<U> context) Called when the subject explicitly logs out.
-
Method Details
-
onLogin
Called after a successful login.The default returns
SessionDecision.Continue.INSTANCE. Implementations that want to rotate the session id after login should returnSessionDecision.Invalidatewith a target route — the adapter then closes the old session and the next request creates a fresh one.- Parameters:
context- session view at the moment of login- Returns:
- decision for the post-login navigation
-
onLogout
Called when the subject explicitly logs out.The default is a no-op; implementations that emit audit events for logout should override or delegate.
- Parameters:
context- session view at the moment of logout
-
evaluate
Pure-query lifetime check used by the VaadinSessionLifetimeListenerand the REST authentication / authorization filters.Distinct from
beforeNavigation(SessionContext)in two ways:- Input is the minimal
SessionMetadatarecord —subjectId,createdAt,lastActivityAt. No subject reference, no attribute bag, no client address. - Output is the minimal
SessionPolicyDecisionsealed type —Active,IdleTimeout, orAbsoluteLifetimeExceeded. The adapter decides what to do with each (Vaadin reroute, REST 401, …).
The default returns
SessionPolicyDecision.active()so policies that only care about the lifecycle hooks remain valid. Implementations with timeout logic —TimeoutSessionPolicy— override this method.- Parameters:
metadata- current session view- Returns:
- decision; never
null
- Input is the minimal
-