Class CookieUtils
- java.lang.Object
-
- com.sun.identity.saml2.idpdiscovery.CookieUtils
-
public class CookieUtils extends Object
Implements utility methods for handling Cookie.
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceBundlebundlestatic StringBUNDLE_NAMEstatic Debugdebug
-
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 StringgetCookieSameSite()Returns property value of "org.openidentityplatform.openam.cookie.samesite"static StringgetCookieValueFromReq(jakarta.servlet.http.HttpServletRequest req, String name)Gets value of cookie that has mached name in servlet requeststatic StringgetPreferCookieName(String reqURI)Gets the preferred cookie name based on the HttpRequest URI.static booleanisCookieHttpOnly()Gets property value of "com.sun.identity.cookie.httponly"static booleanisCookieSecure()Gets property value of "com.iplanet.am.cookie.secure"static booleanisSAML2(jakarta.servlet.http.HttpServletRequest req)static jakarta.servlet.http.CookienewCookie(String name, String value)Constructs a cookie with a specified name and value.static jakarta.servlet.http.CookienewCookie(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.CookienewCookie(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.CookienewCookie(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.CookienewCookie(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 voidsendError(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, int httpStatusCode, String errorCode, String errorMsg)Sends to error page URL for processing.
-
-
-
Field Detail
-
debug
public static Debug debug
-
BUNDLE_NAME
public static final String BUNDLE_NAME
- See Also:
- Constant Field Values
-
bundle
public static ResourceBundle bundle
-
-
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 requestname- 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 cookievalue- 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 cookievalue- a String specifying the value of the cookiemaxAge- 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 cookievalue- a String specifying the value of the cookiepath- 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 cookievalue- a String specifying the value of the cookiepath- a String specifying a pathdomain- a String containing the 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)
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 cookievalue- a String specifying the value of the cookiemaxAge- an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookiepath- a String specifying a pathdomain- 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 objectresponse- HttpServletResponse objecthttpStatusCode- Http Status codeerrorCode- Error codeerrorMsg- 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-
-
-