Package com.sun.identity.shared.encode
Class CookieUtils
- java.lang.Object
-
- com.sun.identity.shared.encode.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 voidaddCookieToResponse(jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.http.Cookie cookie)Add cookie to HttpServletResponse as custom headerstatic StringcheckDoubleQuote(String cookie)Check cookie value whether it has double quote or not.static StringgetAmCookieName()Gets property value of "com.iplanet.am.cookie.name"static StringgetAmPCookieName()Returns property value of "com.iplanet.am.pcookie.name"static SetgetCdssoCookiedomain()Returns property value of "com.iplanet.services.cdsso.cookiedomain"static jakarta.servlet.http.Cookie[]getCookieArrayFromReq(jakarta.servlet.http.HttpServletRequest req)Gets Array of cookie in servlet request.static jakarta.servlet.http.CookiegetCookieFromReq(jakarta.servlet.http.HttpServletRequest req, String name)Gets cookie object that has mached name in servlet requeststatic StringgetCookieSameSite()Returns property value of "org.openidentityplatform.openam.cookie.samesite"static StringgetCookieValue(jakarta.servlet.http.Cookie cookie)Returns normalized value of cookiestatic StringgetCookieValueFromReq(jakarta.servlet.http.HttpServletRequest req, String name)Returns value of cookie that has mached name in servlet requeststatic StringgetFedCookieName()Returns property value of "com.sun.identity.federation.fedCookieName"static Set<String>getMatchingCookieDomains(jakarta.servlet.http.HttpServletRequest request, Collection<String> cookieDomains)Matches the provided cookie domains against the current request's domain and returns the resulting set of matching cookie domains if the 'com.sun.identity.authentication.setCookieToAllDomains' advanced property is set to false.static Map<String,String>getRequestCookies(jakarta.servlet.http.HttpServletRequest request)This method creates Map from the name values of cookies present in the givenHttpServletRequeststatic booleanisCookieHttpOnly()Returns property value of "com.sun.identity.cookie.httponly"static booleanisCookieSecure()Returns property value of "com.iplanet.am.cookie.secure"static jakarta.servlet.http.CookienewCookie(String name, String value)Returns a cookie with a specified name and value.static jakarta.servlet.http.CookienewCookie(String name, String value, int maxAge)Returns a cookie with a specified name and value and sets the maximum age of the cookie in seconds.static jakarta.servlet.http.CookienewCookie(String name, String value, int maxAge, String path, String domain)Returns 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.CookienewCookie(String name, String value, String path)Returns 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.CookienewCookie(String name, String value, String path, String domain)Returns 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.
-
-
-
Method Detail
-
getAmCookieName
public static String getAmCookieName()
Gets property value of "com.iplanet.am.cookie.name"- Returns:
- the property value of "com.iplanet.am.cookie.name"
-
getAmPCookieName
public static String getAmPCookieName()
Returns property value of "com.iplanet.am.pcookie.name"- Returns:
- the property value of "com.iplanet.am.pcookie.name"
-
getCdssoCookiedomain
public static Set getCdssoCookiedomain()
Returns property value of "com.iplanet.services.cdsso.cookiedomain"- Returns:
- the property value of "com.iplanet.services.cdsso.cookiedomain"
-
getFedCookieName
public static String getFedCookieName()
Returns property value of "com.sun.identity.federation.fedCookieName"- Returns:
- the property value of "com.sun.identity.federation.fedCookieName"
-
isCookieSecure
public static boolean isCookieSecure()
Returns property value of "com.iplanet.am.cookie.secure"- Returns:
- the property value of "com.iplanet.am.cookie.secure"
-
isCookieHttpOnly
public static boolean isCookieHttpOnly()
Returns 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"
-
getCookieValueFromReq
public static String getCookieValueFromReq(jakarta.servlet.http.HttpServletRequest req, String name)
Returns value of cookie that has mached name in servlet request- Parameters:
req- HTTP Servlet Request.name- Name in servlet request- Returns:
- value of that name of cookie
-
getCookieFromReq
public static jakarta.servlet.http.Cookie getCookieFromReq(jakarta.servlet.http.HttpServletRequest req, String name)Gets cookie object that has mached name in servlet request- Parameters:
req- HTTP Servlet Request.name- Name in servlet request- Returns:
- value of that name of cookie
-
getCookieValue
public static String getCookieValue(jakarta.servlet.http.Cookie cookie)
Returns normalized value of cookie- Parameters:
cookie- Cookie object.- Returns:
- normalized value of cookie.
-
getCookieArrayFromReq
public static jakarta.servlet.http.Cookie[] getCookieArrayFromReq(jakarta.servlet.http.HttpServletRequest req)
Gets Array of cookie in servlet request.- Parameters:
req- HTTP Servlet Request.
-
getRequestCookies
public static Map<String,String> getRequestCookies(jakarta.servlet.http.HttpServletRequest request)
This method creates Map from the name values of cookies present in the givenHttpServletRequest- Parameters:
request- reference toHttpServletRequest- Returns:
- Map containing name value pairs from cookies present
-
newCookie
public static jakarta.servlet.http.Cookie newCookie(String name, String value)
Returns a cookie with a specified name and value.- Parameters:
name- Name of the cookie.value- Value of the cookie.- Returns:
- constructed cookie.
-
newCookie
public static jakarta.servlet.http.Cookie newCookie(String name, String value, int maxAge)
Returns a cookie with a specified name and value and sets the maximum age of the cookie in seconds.- Parameters:
name- Name of the cookievalue- Value of the cookiemaxAge- 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)
Returns 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- Name of the cookievalue- Value of the cookiepath- Path- Returns:
- constructed cookie
-
newCookie
public static jakarta.servlet.http.Cookie newCookie(String name, String value, String path, String domain)
Returns 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- Name of the cookievalue- Value of the cookiepath- Pathdomain- Domain name within which this cookie is visible; form is according toRFC 2109- Returns:
- constructed cookie
-
newCookie
public static jakarta.servlet.http.Cookie newCookie(String name, String value, int maxAge, String path, String domain)
Returns 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- Name of the cookievalue- Value of the cookiemaxAge- Maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie.path- Pathdomain- Domain name within which this cookie is visible; form is according toRFC 2109- Returns:
- constructed cookie
-
checkDoubleQuote
public static String checkDoubleQuote(String cookie)
Check cookie value whether it has double quote or not. Remove start / ending double quote from cookie and returns cookie value only.- Parameters:
cookie- Value of the Cookie- Returns:
- cookie value without double quote
-
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-
-
getMatchingCookieDomains
public static Set<String> getMatchingCookieDomains(jakarta.servlet.http.HttpServletRequest request, Collection<String> cookieDomains)
Matches the provided cookie domains against the current request's domain and returns the resulting set of matching cookie domains if the 'com.sun.identity.authentication.setCookieToAllDomains' advanced property is set to false.- Parameters:
request- The HTTP request.cookieDomains- The configured cookie domains to match against.- Returns:
- The set of matching cookie domains. May contain null.
-
-