Class CookieUtils


  • public class CookieUtils
    extends Object
    Implements utility methods for handling Cookie.

    • Constructor Summary

      Constructors 
      Constructor Description
      CookieUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addCookieToResponse​(jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.http.Cookie cookie)
      Add cookie to HttpServletResponse as custom header
      static String getCookieSameSite()
      Returns property value of "org.openidentityplatform.openam.cookie.samesite"
      static String getCookieValueFromReq​(jakarta.servlet.http.HttpServletRequest req, String name)
      Gets value of cookie that has mached name in servlet request
      static String getPreferCookieName​(String reqURI)
      Gets the preferred cookie name based on the HttpRequest URI.
      static boolean isCookieHttpOnly()
      Gets property value of "com.sun.identity.cookie.httponly"
      static boolean isCookieSecure()
      Gets property value of "com.iplanet.am.cookie.secure"
      static boolean isSAML2​(jakarta.servlet.http.HttpServletRequest req)  
      static jakarta.servlet.http.Cookie newCookie​(String name, String value)
      Constructs a cookie with a specified name and value.
      static jakarta.servlet.http.Cookie newCookie​(String name, String value, int maxAge)
      Constructs a cookie with a specified name and value and sets the maximum age of the cookie in seconds.
      static jakarta.servlet.http.Cookie newCookie​(String name, String value, int maxAge, String path, String domain)
      Constructs a cookie with a specified name and value and sets the maximum age of the cookie in seconds and sets a path for the cookie to which the client should return the cookie and sets the domain within which this cookie should be presented.
      static jakarta.servlet.http.Cookie newCookie​(String name, String value, String path)
      Constructs a cookie with a specified name and value and sets a path for the cookie to which the client should return the cookie.
      static jakarta.servlet.http.Cookie newCookie​(String name, String value, String path, String domain)
      Constructs a cookie with a specified name and value and sets a path for the cookie to which the client should return the cookie and sets the domain within which this cookie should be presented.
      static void sendError​(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int httpStatusCode, String errorCode, String errorMsg)
      Sends to error page URL for processing.
    • Constructor Detail

      • CookieUtils

        public CookieUtils()
    • Method Detail

      • isCookieSecure

        public static boolean isCookieSecure()
        Gets property value of "com.iplanet.am.cookie.secure"
        Returns:
        the property value of "com.iplanet.am.cookie.secure"
      • isCookieHttpOnly

        public static boolean isCookieHttpOnly()
        Gets property value of "com.sun.identity.cookie.httponly"
        Returns:
        the property value of "com.sun.identity.cookie.httponly"
      • getCookieSameSite

        public static String getCookieSameSite()
        Returns property value of "org.openidentityplatform.openam.cookie.samesite"
        Returns:
        the property value of "org.openidentityplatform.openam.cookie.samesite"
      • isSAML2

        public static boolean isSAML2​(jakarta.servlet.http.HttpServletRequest req)
      • getCookieValueFromReq

        public static String getCookieValueFromReq​(jakarta.servlet.http.HttpServletRequest req,
                                                   String name)
        Gets value of cookie that has mached name in servlet request
        Parameters:
        req - HttpServletRequest request
        name - cookie name in servlet request
        Returns:
        value of that name of cookie
      • newCookie

        public static jakarta.servlet.http.Cookie newCookie​(String name,
                                                            String value)
        Constructs a cookie with a specified name and value.
        Parameters:
        name - a String specifying the name of the cookie
        value - a String specifying the value of the cookie
        Returns:
        constructed cookie
      • newCookie

        public static jakarta.servlet.http.Cookie newCookie​(String name,
                                                            String value,
                                                            int maxAge)
        Constructs a cookie with a specified name and value and sets the maximum age of the cookie in seconds.
        Parameters:
        name - a String specifying the name of the cookie
        value - a String specifying the value of the cookie
        maxAge - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie
        Returns:
        constructed cookie
      • newCookie

        public static jakarta.servlet.http.Cookie newCookie​(String name,
                                                            String value,
                                                            String path)
        Constructs a cookie with a specified name and value and sets a path for the cookie to which the client should return the cookie.
        Parameters:
        name - a String specifying the name of the cookie
        value - a String specifying the value of the cookie
        path - a String specifying a path
        Returns:
        constructed cookie
      • newCookie

        public static jakarta.servlet.http.Cookie newCookie​(String name,
                                                            String value,
                                                            String path,
                                                            String domain)
        Constructs a cookie with a specified name and value and sets a path for the cookie to which the client should return the cookie and sets the domain within which this cookie should be presented.
        Parameters:
        name - a String specifying the name of the cookie
        value - a String specifying the value of the cookie
        path - a String specifying a path
        domain - a String containing the domain name within which this cookie is visible; form is according to RFC 2109
        Returns:
        constructed cookie
      • newCookie

        public static jakarta.servlet.http.Cookie newCookie​(String name,
                                                            String value,
                                                            int maxAge,
                                                            String path,
                                                            String domain)
        Constructs a cookie with a specified name and value and sets the maximum age of the cookie in seconds and sets a path for the cookie to which the client should return the cookie and sets the domain within which this cookie should be presented.
        Parameters:
        name - a String specifying the name of the cookie
        value - a String specifying the value of the cookie
        maxAge - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie
        path - a String specifying a path
        domain - a String containing the domain name within which this cookie is visible; form is according to RFC 2109
        Returns:
        constructed cookie
      • getPreferCookieName

        public static String getPreferCookieName​(String reqURI)
        Gets the preferred cookie name based on the HttpRequest URI.
        Parameters:
        reqURI - a String specifying the HttpRequest URI.
        Returns:
        the preferred cookie name. _saml_idp if the HttpRequest URI matches the SAML2 reader or writer servlet uri. _liberty_idp if the HttpRequest URI matches the IDFF reader or writer servlet uri. return empty string if no above match found. return null if the input HttpRequest uri is null or empty.
      • sendError

        public static void sendError​(jakarta.servlet.http.HttpServletRequest request,
                                     jakarta.servlet.http.HttpServletResponse response,
                                     int httpStatusCode,
                                     String errorCode,
                                     String errorMsg)
        Sends to error page URL for processing. If the error page is hosted in the same web application, forward is used with parameters. Otherwise, redirection is used with parameters. Three parameters are passed to the error URL: -- errorcode : Error key, this is the I18n key of the error message. -- httpstatuscode : Http status code for the error -- message : detailed I18n'd error message
        Parameters:
        request - HttpServletRequest object
        response - HttpServletResponse object
        httpStatusCode - Http Status code
        errorCode - Error code
        errorMsg - Detailed error message
      • addCookieToResponse

        public static void addCookieToResponse​(jakarta.servlet.http.HttpServletResponse response,
                                               jakarta.servlet.http.Cookie cookie)
        Add cookie to HttpServletResponse as custom header
        Parameters:
        response -
        cookie -