Package org.springframework.web.server.session

# Class CookieWebSessionIdResolver

java.lang.Object
org.springframework.web.server.session.CookieWebSessionIdResolver

All Implemented Interfaces:
  `WebSessionIdResolver`

public class CookieWebSessionIdResolver extends Object implements WebSessionIdResolver
Cookie-based `WebSessionIdResolver`.

Since:
  5.0
Author:
  Rossen Stoyanchev, Brian Clozel

## Constructor Summary

Constructors
Constructor
Description
`CookieWebSessionIdResolver()`

## Method Summary

Modifier and Type
Method
Description
`void`
`addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder> initializer)`
Add a `Consumer` to further initialize the session id cookie after `getCookieName()` and `getCookieMaxAge()` are applied.
`void`
`expireSession(ServerWebExchange exchange)`
Instruct the client to end the current session.
`Duration`
`getCookieMaxAge()`
Get the configured "Max-Age" for the session id cookie.
`String`
`getCookieName()`
Get the configured cookie name.
`List<String>`
`resolveSessionIds(ServerWebExchange exchange)`
Resolve the session IDs associated with the request.
`void`
`setCookieMaxAge(Duration maxAge)`
Set the "Max-Age" attribute for the session id cookie.
`void`
`setCookieName(String cookieName)`
Set the name for the session id cookie.
`void`
`setSessionId(ServerWebExchange exchange, String id)`
Send the given session ID to the client.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CookieWebSessionIdResolver

public CookieWebSessionIdResolver()

## Method Details

### setCookieName

public void setCookieName(String cookieName)
Set the name for the session id cookie.

By default set to "SESSION".

Parameters:
  `cookieName` - the cookie name

### getCookieName

public String getCookieName()
Get the configured cookie name.

### setCookieMaxAge

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` - the maxAge duration value
See Also:
  - `ResponseCookie.getMaxAge()`

### getCookieMaxAge

public Duration getCookieMaxAge()
Get the configured "Max-Age" for the session id cookie.

### addCookieInitializer

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 to initialize the cookie with
Since:
  5.1

### resolveSessionIds

public List<String> resolveSessionIds(ServerWebExchange exchange)
Description copied from interface: `WebSessionIdResolver`
Resolve the session IDs associated with the request.

Specified by:
  `resolveSessionIds` in interface `WebSessionIdResolver`
Parameters:
  `exchange` - the current exchange
Returns:
  the session IDs or an empty list

### setSessionId

public void setSessionId(ServerWebExchange exchange, String id)
Description copied from interface: `WebSessionIdResolver`
Send the given session ID to the client.

Specified by:
  `setSessionId` in interface `WebSessionIdResolver`
Parameters:
  `exchange` - the current exchange
  `id` - the session ID

### expireSession

public void expireSession(ServerWebExchange exchange)
Description copied from interface: `WebSessionIdResolver`
Instruct the client to end the current session.

Specified by:
  `expireSession` in interface `WebSessionIdResolver`
Parameters:
  `exchange` - the current exchange