Class AbstractNiceCookie

java.lang.Object
ch.tocco.nice2.web.core.api.servlet.AbstractNiceCookie
Direct Known Subclasses:
AuthCookie, JwtCookie

public abstract class AbstractNiceCookie extends Object
An abstract cookie class to build a cookie and add it to a HttpServletResponse.

The javax.servlet.http.Cookie misses the functionality to set an exact expiration date, or to add a number of seconds based on the CLIENT's time.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    protected @Nullable String
     
    protected @Nullable org.joda.time.DateTime
    Null means it's a session cookie.
    protected org.springframework.boot.web.server.Cookie.SameSite
     
    protected Boolean
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractNiceCookie(org.springframework.boot.web.server.Cookie.SameSite sameSiteMode, Boolean secure)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addToResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Adds the cookie to the response.
    protected abstract String
     
    protected abstract List<String>
    getSpecificTokens(jakarta.servlet.http.HttpServletRequest request)
     
    void
    setExpires(int seconds, org.joda.time.DateTime relativeToThisGmtDate)
     
    protected void
    Allows to verify the current cookie configuration for SameSite and Secure combinations.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • content

      @Nullable protected @Nullable String content
    • sameSiteMode

      protected org.springframework.boot.web.server.Cookie.SameSite sameSiteMode
    • secure

      protected Boolean secure
    • addedToResponse

      protected boolean addedToResponse
    • expires

      @Nullable protected @Nullable org.joda.time.DateTime expires
      Null means it's a session cookie. Otherwise, the gmt date is passed on to the client.
  • Constructor Details

    • AbstractNiceCookie

      protected AbstractNiceCookie(org.springframework.boot.web.server.Cookie.SameSite sameSiteMode, Boolean secure)
  • Method Details

    • setExpires

      public void setExpires(int seconds, org.joda.time.DateTime relativeToThisGmtDate)
      Parameters:
      seconds - A number > 0.
    • addToResponse

      public void addToResponse(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Adds the cookie to the response.

      This method may only be called once. Also, no more modification may be made to the class afterward.

    • verifyConfiguration

      protected void verifyConfiguration()
      Allows to verify the current cookie configuration for SameSite and Secure combinations.
    • getSpecificTokens

      protected abstract List<String> getSpecificTokens(jakarta.servlet.http.HttpServletRequest request)
    • getName

      protected abstract String getName()