Top Description Fields Constructors Methods
org.springframework.web.server.session

public Class CookieWebSessionIdResolver

extends Object
implements WebSessionIdResolver
Class Inheritance
All Implemented Interfaces
org.springframework.web.server.session.WebSessionIdResolver
Imports
java.time.Duration, java.util.Collections, .List, java.util.function.Consumer, org.springframework.http.HttpCookie, .ResponseCookie, org.springframework.lang.Nullable, org.springframework.util.Assert, .MultiValueMap, org.springframework.web.server.ServerWebExchange

Cookie-based WebSessionIdResolver.
Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private Duration
private String
private Consumer<ResponseCookie.ResponseCookieBuilder>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder>
consumer to initialize the cookie with
initializer
)

Add a Consumer to further initialize the session id cookie after getCookieName() and getCookieMaxAge() are applied.

public void
expireSession(ServerWebExchange
the current exchange
exchange
)

Implements org.springframework.web.server.session.WebSessionIdResolver.expireSession.

Instruct the client to end the current session.

public Duration
getCookieMaxAge()

Get the configured "Max-Age" for the session id cookie.

public String
getCookieName()

Get the configured cookie name.

private ResponseCookie.ResponseCookieBuilder
public List<String>
resolveSessionIds(ServerWebExchange
the current exchange
exchange
)

Implements org.springframework.web.server.session.WebSessionIdResolver.resolveSessionIds.

Resolve the session IDs associated with the request.

public void
setCookieMaxAge(Duration
the maxAge duration value
maxAge
)

Set the "Max-Age" attribute for the session id cookie.

public void
setCookieName(String
the cookie name
cookieName
)

Set the name for the session id cookie.

public void
setSessionId(ServerWebExchange
the current exchange
exchange
,
String
the session ID
id
)

Implements org.springframework.web.server.session.WebSessionIdResolver.setSessionId.

Send the given session ID to the client.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cookieMaxAgeback to summary
private Duration cookieMaxAge
cookieNameback to summary
private String cookieName
initializerback to summary
private Consumer<ResponseCookie.ResponseCookieBuilder> initializer
Annotations
@Nullable

Constructor Detail

CookieWebSessionIdResolverback to summary
public CookieWebSessionIdResolver()

Method Detail

addCookieInitializerback to summary
public void addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder> initializer)

Add a Consumer to further initialize the session id cookie after getCookieName() and getCookieMaxAge() are applied.

Parameters
initializer:Consumer<ResponseCookie.ResponseCookieBuilder>

consumer to initialize the cookie with

Since
5.1
expireSessionback to summary
public void expireSession(ServerWebExchange exchange)

Implements org.springframework.web.server.session.WebSessionIdResolver.expireSession.

Doc from org.springframework.web.server.session.WebSessionIdResolver.expireSession.

Instruct the client to end the current session.

Parameters
exchange:ServerWebExchange

the current exchange

Annotations
@Override
getCookieMaxAgeback to summary
public Duration getCookieMaxAge()

Get the configured "Max-Age" for the session id cookie.

getCookieNameback to summary
public String getCookieName()

Get the configured cookie name.

initCookieback to summary
private ResponseCookie.ResponseCookieBuilder initCookie(ServerWebExchange exchange, String id)
resolveSessionIdsback to summary
public List<String> resolveSessionIds(ServerWebExchange exchange)

Implements org.springframework.web.server.session.WebSessionIdResolver.resolveSessionIds.

Doc from org.springframework.web.server.session.WebSessionIdResolver.resolveSessionIds.

Resolve the session IDs associated with the request.

Parameters
exchange:ServerWebExchange

the current exchange

Returns:List<String>

the session IDs or an empty list

Annotations
@Override
setCookieMaxAgeback to summary
public void setCookieMaxAge(Duration maxAge)

Set the "Max-Age" attribute for the session id cookie.

By default set to -1 in which case the cookie is removed when the browser is closed.

Parameters
maxAge:Duration

the maxAge duration value

See Also
ResponseCookie#getMaxAge()
setCookieNameback to summary
public void setCookieName(String cookieName)

Set the name for the session id cookie.

By default set to "SESSION".

Parameters
cookieName:String

the cookie name

setSessionIdback to summary
public void setSessionId(ServerWebExchange exchange, String id)

Implements org.springframework.web.server.session.WebSessionIdResolver.setSessionId.

Doc from org.springframework.web.server.session.WebSessionIdResolver.setSessionId.

Send the given session ID to the client.

Parameters
exchange:ServerWebExchange

the current exchange

id:String

the session ID

Annotations
@Override