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 Details

    • CookieWebSessionIdResolver

      public CookieWebSessionIdResolver()
  • Method Details

    • setCookieName

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

      By default set to "SESSION".

      Parameters:
      cookieName - the cookie name
    • getCookieName

      public String getCookieName()
      Return the configured cookie name.
    • setCookieMaxAge

      public void setCookieMaxAge(Duration maxAge)
      Set the value for the "Max-Age" attribute of the cookie that holds the session id. For the range of values see ResponseCookie.getMaxAge().

      By default set to -1.

      Parameters:
      maxAge - the maxAge duration value
    • getCookieMaxAge

      public Duration getCookieMaxAge()
      Return the configured "Max-Age" attribute value for the session cookie.
    • addCookieInitializer

      public void addCookieInitializer(Consumer<ResponseCookie.ResponseCookieBuilder> initializer)
      Add a Consumer for a ResponseCookieBuilder that will be invoked for each cookie being built, just before the call to build().
      Parameters:
      initializer - consumer for a cookie builder
      Since:
      5.1
    • resolveSessionIds

      public List<String> resolveSessionIds(ServerWebExchange exchange)
      Description copied from interface: WebSessionIdResolver
      Resolve the session id's associated with the request.
      Specified by:
      resolveSessionIds in interface WebSessionIdResolver
      Parameters:
      exchange - the current exchange
      Returns:
      the session id's 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