public interface WebSession
The creation of a WebSession
instance does not automatically start
a session thus causing the session id to be sent to the client (typically via
a cookie). A session starts implicitly when session attributes are added.
A session may also be created explicitly via start()
.
Modifier and Type | Method and Description |
---|---|
reactor.core.publisher.Mono<Void> |
changeSessionId()
Generate a new id for the session and update the underlying session
storage to reflect the new id.
|
default <T> T |
getAttribute(String name)
Return the session attribute value if present.
|
default <T> T |
getAttributeOrDefault(String name,
T defaultValue)
Return the session attribute value, or a default, fallback value.
|
Map<String,Object> |
getAttributes()
Return a map that holds session attributes.
|
Instant |
getCreationTime()
Return the time when the session was created.
|
String |
getId()
Return a unique session identifier.
|
Instant |
getLastAccessTime()
Return the last time of session access as a result of user activity such
as an HTTP request.
|
Duration |
getMaxIdleTime()
Return the maximum time after the
lastAccessTime before a session expires. |
default <T> T |
getRequiredAttribute(String name)
Return the session attribute value or if not present raise an
IllegalArgumentException . |
reactor.core.publisher.Mono<Void> |
invalidate()
Invalidate the current session and clear session storage.
|
boolean |
isExpired()
Return
true if the session expired after maxIdleTime elapsed. |
boolean |
isStarted()
Whether a session with the client has been started explicitly via
start() or implicitly by adding session attributes. |
reactor.core.publisher.Mono<Void> |
save()
Save the session through the
WebSessionStore as follows:
If the session is new (i.e. |
void |
setMaxIdleTime(Duration maxIdleTime)
Configure the max amount of time that may elapse after the
lastAccessTime before a session is considered
expired. |
void |
start()
Force the creation of a session causing the session id to be sent when
save() is called. |
String getId()
@Nullable default <T> T getAttribute(String name)
T
- the attribute typename
- the attribute namedefault <T> T getRequiredAttribute(String name)
IllegalArgumentException
.T
- the attribute typename
- the attribute namedefault <T> T getAttributeOrDefault(String name, T defaultValue)
T
- the attribute typename
- the attribute namedefaultValue
- a default value to return insteadvoid start()
save()
is called.boolean isStarted()
reactor.core.publisher.Mono<Void> changeSessionId()
getId()
reflects the new session id.reactor.core.publisher.Mono<Void> invalidate()
reactor.core.publisher.Mono<Void> save()
WebSessionStore
as follows:
start()
or implicitly by adding
attributes, or otherwise this method should have no effect.
WebSessionStore
,
the implementation for this method must check whether the session was
invalidated
and if so return an error.
Note that this method is not intended for direct use by applications. Instead it is automatically invoked just before the response is committed.
Mono
to indicate completion with success or errorboolean isExpired()
true
if the session expired after maxIdleTime
elapsed.
Typically expiration checks should be automatically made when a session
is accessed, a new WebSession
instance created if necessary, at
the start of request processing so that applications don't have to worry
about expired session by default.
Instant getCreationTime()
Instant getLastAccessTime()
maxIdleTimeInSeconds
this helps to determine when a session is
expired
.void setMaxIdleTime(Duration maxIdleTime)
lastAccessTime
before a session is considered
expired. A negative value indicates the session should not expire.Duration getMaxIdleTime()
lastAccessTime
before a session expires. A negative time indicates the
session doesn't expire.