Class Cookie

java.lang.Object
org.forgerock.http.protocol.Cookie

public class Cookie extends Object
An HTTP cookie. For more information, see the original Netscape specification, RFC 2109 and RFC 2965.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Indicates the SameSite value of the cookie.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new uninitialized cookie.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    Returns the domain for which the cookie is valid.
    Returns the lifetime of the cookie, expressed as the date and time of expiration.
    Returns the lifetime of the cookie, expressed in seconds.
    Returns name of the cookie.
    Returns the subset of URLs on the origin server to which this cookie applies.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    Returns the value of the SameSite attribute.
    Returns the value of the cookie.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    int
     
    Returns true if the user agent should make the cookie inaccessible to client side script.
    Returns true if the user agent should use only secure means to send back this cookie.
    setComment(String comment)
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    setCommentURL(String commentURL)
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    setDomain(String domain)
    Sets the domain for which the cookie is valid.
    setExpires(Date expires)
    Sets the lifetime of the cookie, expressed as the date and time of expiration.
    setHttpOnly(Boolean httpOnly)
    Sets the value indicating whether the user agent should make the cookie inaccessible to client side script.
    Sets the lifetime of the cookie, expressed in seconds.
    Sets the name of the cookie.
    Sets the subset of URLs on the origin server to which this cookie applies.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
    Sets the value of the SameSite attribute.
    Sets the value indicating whether the user agent should use only secure means to send back this cookie.
    Sets the value of the cookie.
    setValueWasQuoted(boolean valueWasQuoted)
    Sets the valueWasQuoted flag to indicate if the original cookie value was enclosed in "", used when recreating the cookie header.
    Deprecated.
    Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
     
    boolean
    Returns true if the cookie value was enclosed in "" when it was parsed, false otherwise.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Cookie

      public Cookie()
      Creates a new uninitialized cookie.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getComment

      @Deprecated public String getComment()
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Returns the intended use of a cookie.
      Returns:
      The intended use of a cookie.
    • getCommentURL

      @Deprecated public String getCommentURL()
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Returns the URL identifying the intended use of a cookie.
      Returns:
      The URL identifying the intended use of a cookie.
    • getDiscard

      @Deprecated public Boolean getDiscard()
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Returns true if the user agent should discard the cookie unconditionally when it terminates.
      Returns:
      true if the user agent should discard the cookie unconditionally when it terminates.
    • getDomain

      public String getDomain()
      Returns the domain for which the cookie is valid.
      Returns:
      The domain for which the cookie is valid.
    • getExpires

      public Date getExpires()
      Returns the lifetime of the cookie, expressed as the date and time of expiration.
      Returns:
      The lifetime of the cookie, expressed as the date and time of expiration.
    • isHttpOnly

      public Boolean isHttpOnly()
      Returns true if the user agent should make the cookie inaccessible to client side script.
      Returns:
      true if the user agent should make the cookie inaccessible to client side script.
    • getMaxAge

      public Integer getMaxAge()
      Returns the lifetime of the cookie, expressed in seconds.
      Returns:
      The lifetime of the cookie, expressed in seconds.
    • getName

      public String getName()
      Returns name of the cookie.
      Returns:
      The name of the cookie.
    • getPath

      public String getPath()
      Returns the subset of URLs on the origin server to which this cookie applies.
      Returns:
      The subset of URLs on the origin server to which this cookie applies.
    • getPort

      @Deprecated public List<Integer> getPort()
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Returns the restricted list of port(s) to which a cookie may be returned.
      Returns:
      The restricted list of port(s) to which a cookie may be returned.
    • isSecure

      public Boolean isSecure()
      Returns true if the user agent should use only secure means to send back this cookie.
      Returns:
      true if the user agent should use only secure means to send back this cookie.
    • getValue

      public String getValue()
      Returns the value of the cookie.
      Returns:
      The value of the cookie.
    • getVersion

      @Deprecated public Integer getVersion()
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Returns the version of the state management mechanism to which this cookie conforms.
      Returns:
      The version of the state management mechanism to which this cookie conforms.
    • valueWasQuoted

      public boolean valueWasQuoted()
      Returns true if the cookie value was enclosed in "" when it was parsed, false otherwise.
      Returns:
      True if the cookie value was enclosed in "" when it was parsed, false otherwise.
    • getSameSite

      public Cookie.SameSite getSameSite()
      Returns the value of the SameSite attribute.
      Returns:
      the SameSite value, or null if not set.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • setComment

      @Deprecated public Cookie setComment(String comment)
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Sets the intended use of a cookie.
      Parameters:
      comment - The intended use of a cookie.
      Returns:
      This cookie.
    • setCommentURL

      @Deprecated public Cookie setCommentURL(String commentURL)
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Sets the URL identifying the intended use of a cookie.
      Parameters:
      commentURL - The URL identifying the intended use of a cookie.
      Returns:
      This cookie.
    • setDiscard

      @Deprecated public Cookie setDiscard(Boolean discard)
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Sets the value indicating whether the user agent should discard the cookie unconditionally when it terminates.
      Parameters:
      discard - true if the user agent should discard the cookie unconditionally when it terminates.
      Returns:
      This cookie.
    • setDomain

      public Cookie setDomain(String domain)
      Sets the domain for which the cookie is valid.
      Parameters:
      domain - The domain for which the cookie is valid.
      Returns:
      This cookie.
    • setExpires

      public Cookie setExpires(Date expires)
      Sets the lifetime of the cookie, expressed as the date and time of expiration.
      Parameters:
      expires - The lifetime of the cookie, expressed as the date and time of expiration.
      Returns:
      This cookie.
    • setHttpOnly

      public Cookie setHttpOnly(Boolean httpOnly)
      Sets the value indicating whether the user agent should make the cookie inaccessible to client side script.
      Parameters:
      httpOnly - true if the user agent should make the cookie inaccessible to client side script.
      Returns:
      this;
    • setMaxAge

      public Cookie setMaxAge(Integer maxAge)
      Sets the lifetime of the cookie, expressed in seconds. Warning: some user agents (including IE/Edge) do not implement Max-Age, so it is recommended you also ensure setExpires(Date) is also called appropriately when calling this method.
      Parameters:
      maxAge - The lifetime of the cookie, expressed in seconds.
      Returns:
      This cookie.
    • setName

      public Cookie setName(String name)
      Sets the name of the cookie.
      Parameters:
      name - The name of the cookie.
      Returns:
      This cookie.
    • setPath

      public Cookie setPath(String path)
      Sets the subset of URLs on the origin server to which this cookie applies.
      Parameters:
      path - The subset of URLs on the origin server to which this cookie applies.
      Returns:
      This cookie.
    • setPort

      @Deprecated public Cookie setPort(List<Integer> port)
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Set the Port attribute as defined per RFC 2965 for Set-Cookie2. The port attribute restricts the port to which a cookie may be returned in a Cookie request header.
      Parameters:
      port - The list of port numbers.
      Returns:
      This cookie.
    • setSecure

      public Cookie setSecure(Boolean secure)
      Sets the value indicating whether the user agent should use only secure means to send back this cookie.
      Parameters:
      secure - true if the user agent should use only secure means to send back this cookie.
      Returns:
      This cookie.
    • setSameSite

      public Cookie setSameSite(Cookie.SameSite sameSite)
      Sets the value of the SameSite attribute.
      Parameters:
      sameSite - the samesite policy value.
      Returns:
      This cookie.
    • setValue

      public Cookie setValue(String value)
      Sets the value of the cookie.
      Parameters:
      value - The value of the cookie.
      Returns:
      This cookie.
    • setVersion

      @Deprecated public Cookie setVersion(Integer version)
      Deprecated.
      Only valid for RFC 2965 cookies ("Cookie2"), which have been deprecated and removed by most clients.
      Sets the version of the state management mechanism to which this cookie conforms.
      Parameters:
      version - The version of the state management mechanism to which this cookie conforms.
      Returns:
      This cookie.
    • setValueWasQuoted

      public Cookie setValueWasQuoted(boolean valueWasQuoted)
      Sets the valueWasQuoted flag to indicate if the original cookie value was enclosed in "", used when recreating the cookie header.
      Parameters:
      valueWasQuoted - Set to true if the original cookie value was enclosed in quotes when the cookie was parsed, used when recreating the cookie header.
      Returns:
      This cookie.
    • toString

      public String toString()
      Overrides:
      toString in class Object