Package org.attribyte.snook.session
Class Sessions
java.lang.Object
org.attribyte.snook.session.Sessions
- All Implemented Interfaces:
com.codahale.metrics.Metric,com.codahale.metrics.MetricSet
- Direct Known Subclasses:
InMemorySessions
Manages sessions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Cookies.CookieKeyThe session cookie key.final com.google.common.collect.ImmutableSet<Cookies.Option> The cookie options.static final Cookies.SameSiteOptionThe default same-site option for the session cookie ().final Cookies.SameSiteOptionThe same-site cookie option. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSessions(Cookies.CookieKey cookieKey, EnumSet<Cookies.Option> cookieOptions, Cookies.SameSiteOption sameSiteOption, int maxAgeSeconds, int cleanIntervalSeconds) Creates a sessions store. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intclearExpired(int maxAgeSeconds) Clear expired tokens.get(com.google.common.hash.HashCode token) Gets a session for a token.protected abstract booleanSaves a session.session(jakarta.servlet.http.HttpServletRequest req) Gets the session for a request.sessionOrNew(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) Gets the session for a request.sessionOrNew(jakarta.servlet.http.HttpServletRequest req, Map<String, Object> data, jakarta.servlet.http.HttpServletResponse resp) Gets the session for a request.voidshutdown()Shutdown sessions.
-
Field Details
-
DEFAULT_SAME_SITE_OPTION
The default same-site option for the session cookie (). -
cookieKey
The session cookie key. -
cookieOptions
The cookie options. -
sameSiteOption
The same-site cookie option.
-
-
Constructor Details
-
Sessions
protected Sessions(Cookies.CookieKey cookieKey, EnumSet<Cookies.Option> cookieOptions, Cookies.SameSiteOption sameSiteOption, int maxAgeSeconds, int cleanIntervalSeconds) Creates a sessions store.- Parameters:
cookieKey- The key for the session cookie.cookieOptions- The cookie options when setting the session cookie.sameSiteOption- The same-site option for the session cookie.maxAgeSeconds- The maximum cookie age in seconds.cleanIntervalSeconds- The cookie clean interval in seconds. If < 1, no cleaning is scheduled.
-
-
Method Details
-
session
Gets the session for a request.- Parameters:
req- The request.- Returns:
- The session or
emptyif none.
-
sessionOrNew
public Session sessionOrNew(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) Gets the session for a request. If none, creates a new (empty) session and sets a response cookie for the session.- Parameters:
req- The request.resp- The response.- Returns:
- The existing or new session.
-
sessionOrNew
public Session sessionOrNew(jakarta.servlet.http.HttpServletRequest req, Map<String, Object> data, jakarta.servlet.http.HttpServletResponse resp) Gets the session for a request. If none, creates a new session with data and sets a response cookie for the session.- Parameters:
req- The request.data- Session data.resp- The response.- Returns:
- The existing or new session.
-
shutdown
public void shutdown()Shutdown sessions. -
get
Gets a session for a token.- Parameters:
token- The token.- Returns:
- The session or
emptyif none.
-
save
Saves a session.- Parameters:
session- The session.- Returns:
- Was the session saved?
-
clearExpired
protected abstract int clearExpired(int maxAgeSeconds) Clear expired tokens.- Parameters:
maxAgeSeconds- The maximum session age in seconds.- Returns:
- The number of expired tokens.
-
getMetrics
- Specified by:
getMetricsin interfacecom.codahale.metrics.MetricSet
-