CookieUtils.java revision 0e107349d3f7763a9c67fb2f32c86c11364c72cf
/**
* 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.9 2009/11/03 00:50:34 madan_ranganath Exp $
*
*/
/**
* Portions Copyrighted 2013-2014 ForgeRock AS
*/
/**
* Implements utility methods for handling Cookie.
* <p>
*/
public class CookieUtils {
static boolean secureCookie =
!= null &&
equalsIgnoreCase("true"));
static boolean cookieHttpOnly =
!= null) &&
equalsIgnoreCase("true"));
static boolean cookieEncoding =
!= null &&
equalsIgnoreCase("true"));
private static int defAge = -1;
// IDP Discovery Resource bundle
// The resource bundle for IDP Discovery implementation.
// error processing URL, read from system property
/**
* Gets property value of "com.iplanet.am.cookie.secure"
*
* @return the property value of "com.iplanet.am.cookie.secure"
*/
public static boolean isCookieSecure() {
return secureCookie;
}
/**
* Gets property value of "com.sun.identity.cookie.httponly"
*
* @return the property value of "com.sun.identity.cookie.httponly"
*/
public static boolean isCookieHttpOnly() {
return cookieHttpOnly;
}
// check this is for idff or saml2
boolean bIsSAML2 = true;
bIsSAML2 = false;
}
return bIsSAML2;
}
/**
* Gets value of cookie that has mached name in servlet request
*
* @param req HttpServletRequest request
* @param name cookie name in servlet request
* @return value of that name of cookie
*/
public static String getCookieValueFromReq(
) {
try {
break;
}
}
// Check property value and it decode value
// Bea, IBM
}
} else {
}
} catch (Exception e) {
}
// check this is for idff or saml2
// take care of the case where there is a '+' in preferred idp
// When '+' is decoded, it became ' ' which is also the seperator
// of different preferred idps
if (cookieValue == null) {
return cookieValue;
} else {
while (st.hasMoreTokens()) {
st.hasMoreTokens()) {
}
}
if (debug.messageEnabled()) {
}
}
}
/**
* Constructs a cookie with a specified name and value.
*
* @param name a String specifying the name of the cookie
*
* @param value a String specifying the value of the cookie
*
* @return constructed cookie
*/
}
/**
* Constructs a cookie with a specified name and value and sets
* the maximum age of the cookie in seconds.
*
* @param name a String specifying the name of the cookie
*
* @param value a String specifying the value of the cookie
*
* @param 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
*
* @return constructed cookie
*/
}
/**
* Constructs 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 a String specifying the name of the cookie
*
* @param value a String specifying the value of the cookie
*
* @param path a String specifying a path
*
* @return constructed cookie
*/
}
/**
* 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.
*
* @param name a String specifying the name of the cookie
*
* @param value a String specifying the value of the cookie
*
* @param path a String specifying a path
*
* @param domain a String containing the domain name within which
* this cookie is visible; form is according to <code>RFC 2109</code>
*
* @return constructed cookie
*/
}
/**
* 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.
*
* @param name a String specifying the name of the cookie
*
* @param value a String specifying the value of the cookie
*
* @param 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
*
* @param path a String specifying a path
*
* @param domain a String containing the domain name within which
* this cookie is visible; form is according to RFC 2109
*
* @return constructed cookie
*/
// Based on property value it does url encoding.
// BEA, IBM
if (cookieEncoding) {
} else {
}
} else {
}
}
return cookie;
}
/**
* Gets the preferred cookie name based on the HttpRequest URI.
*
* @param reqURI a String specifying the HttpRequest URI.
*
* @return 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.
*/
{
return(IDPDiscoveryConstants.IDFF_COOKIE_NAME);
return(IDPDiscoveryConstants.SAML2_COOKIE_NAME);
} else {
return "";
}
} else {
return null;
}
}
/**
* 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
* @param request HttpServletRequest object
* @param response HttpServletResponse object
* @param httpStatusCode Http Status code
* @param errorCode Error code
* @param errorMsg Detailed error message
*/
// no error processing URL set, use sendError
try {
return;
} catch (IOException ioe) {
}
} else {
// construct final URL
jointString = "&";
}
if (debug.messageEnabled()) {
+ newUrl);
}
// send redirect
try {
} catch (IOException e) {
+ "occured while trying to redirect to resource:"
+ newUrl, e);
}
} else {
// use forward
try {
} catch (ServletException e) {
+ "occured while trying to forward to resource:"
+ newUrl, e);
} catch (IOException e) {
+ "occured while trying to forward to resource:"
+ newUrl, e);
}
}
}
}
/**
* Add cookie to HttpServletResponse as custom header
*
* @param response
* @param cookie
*/
return;
}
if (!isCookieHttpOnly()) {
return;
}
// Once JavaEE6 is available, the following code can be simplified
// to be one line response.addCookie(cookie)
} else {
}
}
if (age > -1) {
}
if (CookieUtils.isCookieSecure()) {
}
if (debug.messageEnabled()) {
}
}
}