CookieUtils.java revision 6cf99bcf5206a0fcc9dd9296fc46ac28c3fe8ade
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: CookieUtils.java,v 1.6 2009/10/02 00:08:26 ericow Exp $
*
* Portions Copyrighted 2014-2016 ForgeRock AS.
*/
/**
* Implements utility methods for handling Cookie.
*/
public class CookieUtils {
static boolean secureCookie =
equalsIgnoreCase("true"));
static boolean cookieHttpOnly =
equalsIgnoreCase("true"));
static boolean cookieEncoding =
.equalsIgnoreCase("true"));
private static int defAge = -1;
private static final Method setHttpOnlyMethod;
static {
try {
} catch (NoSuchMethodException nsme) {
}
}
/**
* Gets property value of "com.iplanet.am.cookie.name"
*
* @return the property value of "com.iplanet.am.cookie.name"
*/
public static String getAmCookieName() {
return amCookieName;
}
/**
* Returns property value of "com.iplanet.am.pcookie.name"
*
* @return the property value of "com.iplanet.am.pcookie.name"
*/
public static String getAmPCookieName() {
return amPCookieName;
}
/**
* Returns property value of "com.iplanet.services.cdsso.cookiedomain"
*
* @return the property value of "com.iplanet.services.cdsso.cookiedomain"
*/
public static Set getCdssoCookiedomain() {
if (cookieDomains != null) {
return cookieDomains;
}
return Collections.EMPTY_SET;
}
while (st.hasMoreTokens()) {
}
}
}
/**
* Returns property value of "com.sun.identity.federation.fedCookieName"
*
* @return the property value of "com.sun.identity.federation.fedCookieName"
*/
public static String getFedCookieName() {
return fedCookieName;
}
/**
* Returns property value of "com.iplanet.am.cookie.secure"
*
* @return the property value of "com.iplanet.am.cookie.secure"
*/
public static boolean isCookieSecure() {
return secureCookie;
}
/**
* Returns property value of "com.sun.identity.cookie.httponly"
*
* @return the property value of "com.sun.identity.cookie.httponly"
*/
public static boolean isCookieHttpOnly() {
return cookieHttpOnly;
}
/**
* Returns value of cookie that has mached name in servlet request
*
* @param req HTTP Servlet Request.
* @param name Name in servlet request
* @return value of that name of cookie
*/
public static String getCookieValueFromReq(
) {
} else {
}
return cookieValue;
}
/**
* Gets cookie object that has mached name in servlet request
*
* @param req HTTP Servlet Request.
* @param name Name in servlet request
* @return value of that name of cookie
*/
}
}
}
return null;
}
/**
* Returns normalized value of cookie
*
* @param cookie Cookie object.
* @return normalized value of cookie.
*/
// Check property value and it decode value
// Bea, IBM
}
return cookieValue;
}
/**
* Gets Array of cookie in servlet request.
*
* @param req HTTP Servlet Request.
*/
if (!cookieEncoding) {
return cookies;
}
.getValue());
if (cookieValue != null) {
}
}
}
return cookies;
}
/**
* This method creates Map from the name values of cookies
* present in the given <code>HttpServletRequest</code>
*
* @param request reference to <code>HttpServletRequest</code>
* @return Map containing name value pairs from cookies present
*/
}
}
}
return cookieMap;
}
/**
* Returns a cookie with a specified name and value.
*
* @param name Name of the cookie.
*
* @param value Value of the cookie.
*
* @return constructed cookie.
*/
}
/**
* Returns a cookie with a specified name and value and sets the maximum
* age of the cookie in seconds.
*
* @param name Name of the cookie
* @param value Value of the cookie
* @param maxAge Maximum age of the cookie in seconds; if negative, means
* the cookie is not stored; if zero, deletes the cookie.
* @return constructed cookie
*/
}
/**
* Returns a cookie with a specified name and value and sets a path for
* the cookie to which the client should return the cookie.
*
* @param name Name of the cookie
* @param value Value of the cookie
* @param path Path
* @return constructed cookie
*/
}
/**
* 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.
*
* @param name Name of the cookie
* @param value Value of the cookie
* @param path Path
* @param domain Domain name within which this cookie is visible; form is
* according to <code>RFC 2109</code>
* @return constructed cookie
*/
) {
}
/**
* 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.
*
* @param name Name of the cookie
* @param value Value of the cookie
* @param maxAge Maximum age of the cookie in seconds; if negative, means
* the cookie is not stored; if zero, deletes the cookie.
* @param path Path
* @param domain Domain name within which this cookie is visible; form is
* according to <code>RFC 2109</code>
* @return constructed cookie
*/
int maxAge,
) {
// Based on property value it does url encoding.
// BEA, IBM
} else {
}
} else {
}
}
return cookie;
}
/**
* Check cookie value whether it has double quote or not. Remove start /
* ending double quote from cookie and returns cookie value only.
*
* @param cookie Value of the Cookie
* @return cookie value without double quote
*/
}
return cookie;
}
/**
* Add cookie to HttpServletResponse as custom header
*
* @param response
* @param cookie
*/
return;
}
if (!isCookieHttpOnly()) {
return;
}
if (setHttpOnlyMethod != null) {
try {
return;
} catch (IllegalAccessException iae) {
} catch (InvocationTargetException ite) {
}
}
} else {
}
}
if (age > -1) {
// set Expires as < IE 8 does not support max-age
}
}
if (debug.messageEnabled()) {
}
}
/**
* 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.
*
* @param request The HTTP request.
* @param cookieDomains The configured cookie domains to match against.
* @return The set of matching cookie domains. May contain null.
*/
public static Set<String> getMatchingCookieDomains(HttpServletRequest request, Collection<String> cookieDomains) {
return new HashSet<>(cookieDomains);
}
}
}
return domains;
}
}