Class SessionCookieConfig

java.lang.Object
org.glassfish.grizzly.servlet.SessionCookieConfig
All Implemented Interfaces:
SessionCookieConfig

public class SessionCookieConfig extends Object implements SessionCookieConfig
Class that may be used to configure various properties of cookies used for session tracking purposes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    Obtain the value for a given session cookie attribute.
    Obtain the Map (keys are case insensitive) of all attributes and values, including those set via the attribute specific setters, (excluding version) for this SessionCookieConfig.
    Deprecated. 
    Gets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    int
    Gets the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    Gets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    Gets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    boolean
    Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly.
    boolean
    Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS.
    void
    setAttribute(String name, String value)
    Sets the value for the given session cookie attribute.
    void
    setComment(String comment)
    Deprecated. 
    void
    setDomain(String domain)
    Sets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    void
    setHttpOnly(boolean httpOnly)
    Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as HttpOnly.
    void
    setMaxAge(int maxAge)
    Sets the lifetime (in seconds) for the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    void
    Sets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    void
    Sets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
    void
    setSecure(boolean secure)
    Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as secure.

    Methods inherited from class java.lang.Object

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

    • SessionCookieConfig

      public SessionCookieConfig(WebappContext ctx)
      Constructor
  • Method Details

    • setName

      public void setName(String name)
      Description copied from interface: SessionCookieConfig
      Sets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

      NOTE: Changing the name of session tracking cookies may break other tiers (for example, a load balancing frontend) that assume the cookie name to be equal to the default JSESSIONID, and therefore should only be done cautiously.

      Specified by:
      setName in interface SessionCookieConfig
      Parameters:
      name - the cookie name to use
      Throws:
      IllegalStateException - if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
    • getName

      public String getName()
      Description copied from interface: SessionCookieConfig
      Gets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

      By default, JSESSIONID will be used as the cookie name.

      Specified by:
      getName in interface SessionCookieConfig
      Returns:
      the cookie name set via setName(java.lang.String), or JSESSIONID if setName(java.lang.String) was never called
      See Also:
    • setDomain

      public void setDomain(String domain)
      Description copied from interface: SessionCookieConfig
      Sets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
      Specified by:
      setDomain in interface SessionCookieConfig
      Parameters:
      domain - the cookie domain to use
      Throws:
      IllegalStateException - if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
      See Also:
    • getDomain

      public String getDomain()
      Description copied from interface: SessionCookieConfig
      Gets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
      Specified by:
      getDomain in interface SessionCookieConfig
      Returns:
      the cookie domain set via setDomain(java.lang.String), or null if setDomain(java.lang.String) was never called
      See Also:
    • setPath

      public void setPath(String path)
      Description copied from interface: SessionCookieConfig
      Sets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
      Specified by:
      setPath in interface SessionCookieConfig
      Parameters:
      path - the cookie path to use
      Throws:
      IllegalStateException - if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
      See Also:
    • getPath

      public String getPath()
      Description copied from interface: SessionCookieConfig
      Gets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

      By default, the context path of the ServletContext from which this SessionCookieConfig was acquired will be used.

      Specified by:
      getPath in interface SessionCookieConfig
      Returns:
      the cookie path set via setPath(java.lang.String), or the context path of the ServletContext from which this SessionCookieConfig was acquired if setPath(java.lang.String) was never called
      See Also:
    • setComment

      @Deprecated public void setComment(String comment)
      Deprecated.
      Description copied from interface: SessionCookieConfig
      With the adoption of support for RFC 6265, this method should no longer be used.

      If called, this method has no effect.

      Specified by:
      setComment in interface SessionCookieConfig
      Parameters:
      comment - the cookie comment to use
      Throws:
      IllegalStateException - if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
      See Also:
    • getComment

      @Deprecated public String getComment()
      Deprecated.
      Description copied from interface: SessionCookieConfig
      With the adoption of support for RFC 6265, this method should no longer be used.
      Specified by:
      getComment in interface SessionCookieConfig
      Returns:
      the cookie comment set via setComment(java.lang.String), or null if setComment(java.lang.String) was never called
      See Also:
    • setHttpOnly

      public void setHttpOnly(boolean httpOnly)
      Description copied from interface: SessionCookieConfig
      Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as HttpOnly.

      A cookie is marked as HttpOnly by adding the HttpOnly attribute to it. HttpOnly cookies are not supposed to be exposed to client-side scripting code, and may therefore help mitigate certain kinds of cross-site scripting attacks.

      Specified by:
      setHttpOnly in interface SessionCookieConfig
      Parameters:
      httpOnly - true if the session tracking cookies created on behalf of the ServletContext from which this SessionCookieConfig was acquired shall be marked as HttpOnly, false otherwise
      Throws:
      IllegalStateException - if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
      See Also:
    • isHttpOnly

      public boolean isHttpOnly()
      Description copied from interface: SessionCookieConfig
      Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly.
      Specified by:
      isHttpOnly in interface SessionCookieConfig
      Returns:
      true if the session tracking cookies created on behalf of the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly, false otherwise
      See Also:
    • setSecure

      public void setSecure(boolean secure)
      Description copied from interface: SessionCookieConfig
      Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as secure.

      One use case for marking a session tracking cookie as secure, even though the request that initiated the session came over HTTP, is to support a topology where the web container is front-ended by an SSL offloading load balancer. In this case, the traffic between the client and the load balancer will be over HTTPS, whereas the traffic between the load balancer and the web container will be over HTTP.

      Specified by:
      setSecure in interface SessionCookieConfig
      Parameters:
      secure - true if the session tracking cookies created on behalf of the ServletContext from which this SessionCookieConfig was acquired shall be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS, and false if they shall be marked as secure only if the request that initiated the corresponding session was also secure
      Throws:
      IllegalStateException - if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
      See Also:
    • isSecure

      public boolean isSecure()
      Description copied from interface: SessionCookieConfig
      Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS.
      Specified by:
      isSecure in interface SessionCookieConfig
      Returns:
      true if the session tracking cookies created on behalf of the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS, and false if they will be marked as secure only if the request that initiated the corresponding session was also secure
      See Also:
    • setMaxAge

      public void setMaxAge(int maxAge)
      Description copied from interface: SessionCookieConfig
      Sets the lifetime (in seconds) for the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
      Specified by:
      setMaxAge in interface SessionCookieConfig
      Parameters:
      maxAge - the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
      See Also:
    • getMaxAge

      public int getMaxAge()
      Description copied from interface: SessionCookieConfig
      Gets the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

      By default, -1 is returned.

      Specified by:
      getMaxAge in interface SessionCookieConfig
      Returns:
      the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired, or -1 (the default)
      See Also:
    • setAttribute

      public void setAttribute(String name, String value)
      Description copied from interface: SessionCookieConfig
      Sets the value for the given session cookie attribute. When a value is set via this method, the value returned by the attribute specific getter (if any) must be consistent with the value set via this method.
      Specified by:
      setAttribute in interface SessionCookieConfig
      Parameters:
      name - Name of attribute to set, case insensitive
      value - Value of attribute
    • getAttribute

      public String getAttribute(String name)
      Description copied from interface: SessionCookieConfig
      Obtain the value for a given session cookie attribute. Values returned from this method must be consistent with the values set and returned by the attribute specific getters and setters in this class.
      Specified by:
      getAttribute in interface SessionCookieConfig
      Parameters:
      name - Name of attribute to return, case insensitive
      Returns:
      Value of specified attribute
    • getAttributes

      public Map<String,String> getAttributes()
      Description copied from interface: SessionCookieConfig
      Obtain the Map (keys are case insensitive) of all attributes and values, including those set via the attribute specific setters, (excluding version) for this SessionCookieConfig.
      Specified by:
      getAttributes in interface SessionCookieConfig
      Returns:
      A read-only Map of attributes to values, excluding version.