FSUtils.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: FSUtils.java,v 1.10 2009/11/20 23:52:57 ww203982 Exp $
*
*/
/*
* Portions Copyrighted 2014 ForgeRock AS
*/
/**
* This class contain constants used in the SDK.
*/
public class FSUtils {
public static String deploymentURI =
"com.iplanet.am.services.deploymentDescriptor");
public static IFSConstants sc;
public static ResourceBundle bundle =
private static String server_protocol =
private static String server_host =
private static String server_port =
private static int int_server_port = 0;
static {
try {
} catch (NumberFormatException nfe) {
}
}
/**
* Constructor
*/
private FSUtils() {
}
/**
* Sets the locale of the resource bundle
*
*/
try {
} catch (MissingResourceException mre) {
}
}
/**
* Generates an ID String with length of IFSConstants.ID_LENGTH.
* @return string the ID String; or null if it fails.
*/
public static String generateID() {
return null;
}
}
return encodedID;
}
/**
* Generates source ID String
* @param entityID the entity ID of the source site
* @return source ID
*/
try {
} catch (Exception e) {
return null;
}
}
}
/**
* Generates assertion handle.
* @return 20-byte random string to be used to form an artifact.
*/
public static String generateAssertionHandle() {
try {
} catch (Exception e) {
}
}
return result;
}
/**
* Converts a string to Base64 encoded string.
* @param succinctID provider's succinctID string
* @return Base64 encoded string
*/
try {
.trim();
} catch (Exception e) {
"FSUtils:stringToBase64: exception encode input:", e);
}
}
}
return encodedID;
}
/**
* Checks content length of a http request to avoid dos attack.
* In case IDFF inter-op with other IDFF vendor who may not provide content
* length in HttpServletRequest. We decide to support no length restriction
* for Http communication. Here, we use a special value (e.g. 0) to
* indicate that no enforcement is required.
* @param request <code>HttpServletRequest</code> instance to be checked.
* @exception ServletException if context length of the request exceeds
* maximum content length allowed.
*/
throws ServletException
{
// avoid the DOS attack for SOAP messaging
if (maxContentLength != 0) {
if (length == -1) {
}
if (length > maxContentLength) {
if (debug.messageEnabled()) {
"content length too large" + length);
}
throw new ServletException(
}
}
}
/**
* Test if url in argument is
* in the same web container as current opensso web
* apps serving the request.
* @param request HttpServletRequest
* @param url
* @return true if request and url are in the same web container else false
*/
public static boolean isSameContainer(
boolean result = false;
try {
//get source host and port
if (debug.messageEnabled()) {
}
//get target host and port
if (debug.messageEnabled()) {
}
!(sourcePort == targetPort) ||
!(index > 0)) {
if (debug.messageEnabled()) {
+ "Target are not on the same container.");
}
} else {
if (debug.messageEnabled()) {
"Target are on the same container.");
}
result = true;
}
}
return result;
}
/**
* Forwards or redirects to a new URL. This method will do forwarding
* if the target url is in the same web deployment URI as current web
* apps. Otherwise will do redirecting.
* @param request HttpServletRequest
* @param response HttpServletResponse
* @param url the target URL to be forwarded to redirected.
*/
public static void forwardRequest(
{
try {
}
"FSUtils.forwardReqeust: couldn't rewrite url: " +
se.getMessage());
}
}
}
try {
//get source host and port
//get target host and port
/**
* IBM websphere is not able to handle forwards with long urls.
*/
boolean isWebSphere = false;
isWebSphere = true;
}
!(sourcePort == targetPort) ||
{
"Target are not on the same container." +
"Redirecting to target");
return;
} else {
"FSUtils.forwardRequest: Forwarding to :" + resource);
}
try {
} catch (Exception e) {
+ "occured while trying to forward to resource:" +
resource , e);
}
}
}
}
/**
* Returns entity ID from the Succinct ID.
* @param realm The realm under which the entity resides.
* @param succinctID Succinct ID.
* @return String entity ID; or <code>null</code> for failure in
* converting the succinct id to entity id.
*/
private static String getProviderIDFromSuccinctID(
if (succinctID == null) {
return null;
}
try {
if (metaInstance != null) {
}
}
return null;
}
/**
* Finds the preferred IDP from the HttpServletRequest.
* @param realm The realm under which the entity resides.
* @param request HttpServletRequest.
* @return String preferred IDP entity ID; or <code>null</code> for failure
* or unable to find in the request.
*/
public static String findPreferredIDP(
return null;
}
return null;
}
while(st.hasMoreTokens()){
st.hasMoreTokens())
{
}
}
}
/**
* Removes new line characters (useful for Base64 decoding)
* @param s String
* @return result String
*/
char[] chars = s.toCharArray();
for (int i = 0; i < len; i++) {
char c = chars[i];
if (c != '\n') {
}
}
} else {
retString = s;
}
return retString;
}
/**
* Returns an instance of the IDFF meta manager class.
* @return <code>IDFFMetaManager</code> instance; or <code>null</code>
* if it cannot retrieve the instance.
*/
public static IDFFMetaManager getIDFFMetaManager() {
if (metaInstance == null){
synchronized (IDFFMetaManager.class) {
try {
// TODO: generate admin session and pass it in
return metaInstance;
} catch (Exception e) {
+ " Could not create meta Manager", e);
return null;
}
}
}
return metaInstance;
}
/*
* Returns the Authentication Domain URL Mappings for the given
* organization.
* @param orgDN dn of the organization/realm name
* @return authentication domain
*/
return "/";
}
}
} else {
// should be realm name
return "/";
} else {
// error case, but allow to continue
}
} else {
// error case, but allow to continue
}
}
return null;
}
public static boolean needSetLBCookieAndRedirect(
boolean isIDP) {
return false;
}
getlbCookieName());
return false;
}
if (debug.messageEnabled()) {
" lbCookie not set.");
}
// turn off cookie hash redirect by default
"com.sun.identity.federation.cookieHashRedirectEnabled");
return false;
}
if (redirected != null) {
if (debug.messageEnabled()) {
" redirected already and lbCookie not set correctly.");
}
return false;
}
.append("?redirected=1");
if (queryString != null) {
}
try {
if (isIDP) {
} else {
if (samlMessage == null) {
}
}
if (samlMessage == null) {
return false;
}
} else {
return false;
}
return true;
} catch (IOException ioe) {
} catch (SAML2Exception saml2E) {
}
return false;
}
/**
* Gets remote service URLs
* @param request http request
* @return remote service URLs
*/
if (debug.messageEnabled()) {
}
try {
if (debug.messageEnabled()) {
}
if (debug.messageEnabled()) {
}
if (debug.messageEnabled()) {
}
}
if (serverList == null) {
return null;
}
}
}
if (debug.messageEnabled()) {
"remoteServiceURLs = " + remoteServiceURLs);
}
return remoteServiceURLs;
}
/**
* Sets load balancer cookie.
* @param response HttpServletResponse object
*/
try {
} catch (SystemConfigurationException scex) {
if (debug.warningEnabled()) {
}
}
"/", domain);
}
} else {
null);
}
}
}
public static String getlbCookieName() {
"amlbcookie");
}
public static String getlbCookieValue() {
if ((loadBalanceCookieValue == null) ||
if (SystemConfigurationUtil.isServerMode()) {
try {
} catch (SystemConfigurationException scex) {
return null;
}
}
}
return loadBalanceCookieValue;
}
try {
} catch (ServletException sE) {
} catch (IOException ioE) {
}
}
/**
* Handles any exception when attempting to forward.
*
* @param exception
* Thrown and caught exception
* @throws SAML2Exception
* Single general exception that is thrown on
*/
}
}