Class StandardResponseCookie

Object
se.curity.identityserver.sdk.web.cookie.ResponseCookie
se.curity.identityserver.sdk.web.cookie.StandardResponseCookie
All Implemented Interfaces:
Cookie

public final class StandardResponseCookie extends ResponseCookie
A Standard HTTP cookie.

Unlike ExpirableResponseCookie, standard cookies use the max-age attribute to decide whether a cookie is persistent or not.

If max-age is set to a positive value, then the cookie is persistent and lasts for the amount of time given by max-age.

If max-age is set to 0, then the cookie is immediately expired.

If max-age is set to a negative value, or not set at all, then the cookie lasts until the browser session is ended.

Since:
2.1.0
  • Constructor Details

    • StandardResponseCookie

      public StandardResponseCookie(String name, @Nullable String value)
      Create a cookie with the provided name and value.
      Parameters:
      name - the name of the cookie
      value - the value of the cookie
    • StandardResponseCookie

      public StandardResponseCookie(Cookie cookie)
      Create a copy of the provided cookie.
      Parameters:
      cookie - to be copied
  • Method Details

    • setMaxAge

      public void setMaxAge(@Nullable Duration duration)
      Set the max-age of the cookie.

      If set to null, this cookie will last only until the browser session is ended.

      Parameters:
      duration - of time the cookie should live for
    • getMaxAge

      public Optional<Duration> getMaxAge()
      Get the max-age of the cookie.
      Returns:
      the max-age of the cookie. If not present, then this cookie is a session cookie.