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<java.lang.Void> |
changeSessionId()
Generate a new id for the session and update the underlying session
storage to reflect the new id.
|
default <T> T |
getAttribute(java.lang.String name)
Return the session attribute value if present.
|
default <T> T |
getAttributeOrDefault(java.lang.String name,
T defaultValue)
Return the session attribute value, or a default, fallback value.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Return a map that holds session attributes.
|
java.time.Instant |
getCreationTime()
Return the time when the session was created.
|
java.lang.String |
getId()
Return a unique session identifier.
|
java.time.Instant |
getLastAccessTime()
Return the last time of session access as a result of user activity such
as an HTTP request.
|
java.time.Duration |
getMaxIdleTime()
Return the maximum time after the
lastAccessTime before a session expires. |
default <T> T |
getRequiredAttribute(java.lang.String name)
Return the session attribute value or if not present raise an
IllegalArgumentException . |
reactor.core.publisher.Mono<java.lang.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<java.lang.Void> |
save()
Save the session persisting attributes (e.g.
|
void |
setMaxIdleTime(java.time.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. |
java.lang.String getId()
java.util.Map<java.lang.String,java.lang.Object> getAttributes()
@Nullable default <T> T getAttribute(java.lang.String name)
T
- the attribute typename
- the attribute namedefault <T> T getRequiredAttribute(java.lang.String name)
IllegalArgumentException
.T
- the attribute typename
- the attribute namedefault <T> T getAttributeOrDefault(java.lang.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<java.lang.Void> changeSessionId()
getId()
reflects the new session id.reactor.core.publisher.Mono<java.lang.Void> invalidate()
reactor.core.publisher.Mono<java.lang.Void> save()
Note that a session must be started explicitly via start()
or
implicitly by adding attributes or otherwise this method has no effect.
Mono
to indicate completion with success or error
Typically this method should be automatically invoked just before the response is committed so applications don't have to by default.
boolean 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.
java.time.Instant getCreationTime()
java.time.Instant getLastAccessTime()
maxIdleTimeInSeconds
this helps to determine when a session is
expired
.void setMaxIdleTime(java.time.Duration maxIdleTime)
lastAccessTime
before a session is considered
expired. A negative value indicates the session should not expire.java.time.Duration getMaxIdleTime()
lastAccessTime
before a session expires. A negative time indicates the
session doesn't expire.