FSServiceUtils.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: FSServiceUtils.java,v 1.11 2008/11/10 22:56:59 veiming Exp $
*
* Portions Copyrighted 2012-2016 ForgeRock AS.
*/
/**
* Util class to provide methods to manage ID-FF service.
*/
public class FSServiceUtils {
private static boolean signingOn = false;
private static boolean signingOptional = false;
private static final String templatePath =
static {
try {
"could not get factory instance");
ex.printStackTrace ();
}
"com.sun.identity.federation.services.signingOn", "optional");
signingOn = true;
signingOptional = true;
}
};
// constructor
private FSServiceUtils () {
}
/**
* Returns <code>true</code> if signing is enabled; otherwise, it will
* @return <code>true</code> if signing is on; otherwise, return
* <code>false</code>
*/
public static boolean isSigningOn () {
return signingOn;
}
/**
* Returns <code>true</code> if signing is optional else it will return
* specification.
* @return <code>true</code> if signing is optional; otherwise return
* <code>false</code>
*/
public static boolean isSigningOptional () {
return signingOptional;
}
/**
* Returns common login page URL based on the deployment descriptor and
* the meta alias associated with the hosted provider.
* @param metaAlias the meta alias of the hosted provider
* @param resourceUrl resource URL to redirect to
* @param requestId the <code>AuthnRequest</code> Id
* @param request <code>HttpServletRequest</code> object
* @param baseURL deployment base URL
* @return the common login page URL; or <code>null</code> if an error
* occurred during the process.
*/
public static String getCommonLoginPageURL (
{
"metaAlias is null");
return null;
}
try{
}
}
}catch(Exception e){
"Could not obtain local config");
return null;
}
if (hostConfig == null) {
"Could not obtain hosted extended meta.");
return null;
}
} else {
}
} else{
}
}
}
}
}
"FSServiceUtils.getCommonLoginPageURL: List LoginPage: " +
}
return commonLoginPageUrl.toString ();
}
/* Returns <code>URL</code> in the format of:
* <code>protocol://host:port/deployment_descriptor</code>.
* The value of each field is retrieved from
* <code>AMConfig.proeprties</code>.
* @return the string with the combined value instance
*/
public static String getBaseURL () {
"com.iplanet.am.services.deploymentDescriptor");
"com.iplanet.am.server.protocol");
"com.iplanet.am.server.host");
"com.iplanet.am.server.port");
}
/**
* Retrieves meta alias of a provider from http request.
* @param request <code>HttpServletRequest</code> object
* @return meta alias of a provider embeded in the request url
*/
+ uri);
}
if ((index == -1) ||
{
"FSServiceUtil.getMetaAlias no metaAlias in request");
return null;
}
}
/**
* Retrieves locale of a http request.
* @param request <code>HttpServletRequest</code> object
* @return locale of the request; or <code>null</code> if locale cannot
* be retrieved.
*/
+ "null, returning null");
return null;
}
try {
ISSSOToken, "Locale");
"FSServiceUtil.getLocale returning locale from token "
+ returnStr[0]);
}
return returnStr[0];
}
} catch (SessionException ssoe) {
ssoe);
} catch (UnsupportedOperationException ex) {
}
"FSServiceUtil.getLocale returning :locale from request:"
+ returnStr);
}
return returnStr;
}
+ "locale from request either from token or header. returning "
+ "null ");
}
return null;
}
/**
* Returns the base URL for OpenAM services deployment.
* @param request HttpServletRequest
* @return service base url
*/
"com.iplanet.am.services.deploymentDescriptor");
"FSServiceUtil.getServicesBaseURL hostString is " +
}
return amserverURI;
}
/**
* Returns base url of a request.
* @param request <code>HttpServletRequest</code> object
* @return base url
*/
return getBaseURL();
}
}else{
}
return returnStr;
}
return hostStr;
}
/**
* Outputs the DOM representation given as root as XML string.
* @param root The <code>DOM</code> representation to be outputted
* @return string representation of <code>DOM</code> node.
* @exception TransformerException, TransformerConfigurationException,
* FileNotFoundException
*/
public static String printDocument (Node root) throws TransformerException, TransformerConfigurationException,
}
/**
* Converts <code>SOAP</code> message to <code>DOM</code> element.
* @param message <code>SOAP</code> message
* @return <code>DOM</code> element
*/
try{
+ xml);
}
return doc;
} catch (Exception e) {
"FSServiceUtils.createSOAPDOM: Exception: ", e);
return null;
}
}
/**
* Converts <code>DOM</code> document to <code>SOAP</code> message.
* @param doc <code>DOM</code> document
* @return <code>SOAP</code> message
*/
try{
} catch (Exception e) {
+ "Exception: " + e.getMessage ());
return null;
}
}
/**
* Determines whether the request contains LECP header or not.
* @param request <code>HttpServletRequest</code> object
* @return <code>true</code> if the request contains LECP header;
* <code>false</code> otherwise.
*/
while(headerNames.hasMoreElements()) {
}
}
+ lecpHeaderValue);
}
if(lecpHeaderValue == null) {
}
if(lecpHeaderValue != null) {
return true;
} else {
return false;
}
}
/**
* Gets the Affiliation ID for the provider that it belongs.
* @param realm The realm under which the entity resides.
* @param entityID provider's entity ID.
* @return Affiliation ID.
*/
if (metaManager != null) {
return affiliateDescriptor.getAffiliationID();
}
}
return null;
}
/**
* Parses the attribute map configuration and returns as java
* <code>java.util.Map</code>.
* @param list attribute configuration.
* @return configured attribute mapping with key as the SAML
* attribute and the value being the local attribute.
*/
"Input put list is empty");
}
return map;
}
}
}
return map;
}
/**
* Displays error page.
* @param response <code>HttpServletResponse</code> object
* @param commonErrorPage redirect url for error page
* @param errorLocaleString locale string for the error message
* @param remarkLocaleString locale string for the error remark
*/
public static void showErrorPage(
{
char delimiter;
} else {
}
}
try {
} catch (IOException e){
}
}
/**
* Redirects the HTTP request to the Authentication module.
* The authentication URL is built based on the organization that is
* associated with the provider
* @param request <code>HttpServletRequest</code> object that contains the
* request the client has made of the servlet.
* @param response <code>HttpServletResponse</code> object that contains
* the response the servlet sends to the client.
* @param hostedProviderAlias meta alias that identifies the local hosted
* provider
* @exception IOException If an input or output exception occurs
*/
public static void redirectForAuthentication(
throws IOException
{
"Entered FSServiceUtils::redirectForAuthentication");
try {
char authDelimiter;
} else {
}
}
}
return;
} catch (IOException e) {
return;
}
}
/**
* Returns the parameters in the request as a HTTP URL string.
* It returns all the parameters from the original request
* @param request <code>HttpServletRequest</code> object that contains the
* request the client has made of the servlet.
* @return The parameters of the request as String.
*/
private static String getParameterString(
{
while (e.hasMoreElements()) {
}
}
}
return parameterString.toString();
}
/**
* Invoked at the end when an operation is done.
* The isSuccess determines if success message or failure message is
* displayed.
* @param response the <code>HttpServletResponse</code> object
* @param opDoneURL where to go when an operation is done
* @param isSuccess determines the content of the operation-done.jsp
* @param successString success string to be appended to url if
* <code>isSuccess</code> is true.
* @param failureString failure string to be appended to url if
* <code>isSuccess</code> is false.
*/
public static void returnLocallyAfterOperation(
boolean isSuccess,
{
try {
char delimiter;
} else {
}
if (isSuccess) {
} else {
}
return;
} catch(IOException e) {
return;
}
}
/**
* Determines the return location and redirects based on
* federation termination Return URL of the provider that sent the
* termination request
* @param response http response object
* @param retURL operation return url
* @param commonErrorPage where to go if error occurs
* @param errorLocaleString locale string for federation error
* @param remarkLocaleString locale string for federation remark
*/
public static void returnToSource(
{
try {
"as source provider is unknown");
}
return;
} else {
retURL);
}
return;
}
} catch(IOException exx) {
exx);
}
}
/**
* Returns the list of circle of trusts page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @return the list of circle of trusts page URL.
*/
{
}
return tempUrl;
}
/**
* Returns common login page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @return common login page URL.
*/
{
}
return tempUrl;
}
/**
* Returns error page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @param metaAlias hosted provider's meta alias
* @return error page URL.
*/
{
}
return tempUrl;
}
/**
* Returns termination done page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @param metaAlias hosted provider's meta alias
* @return termination done page URL.
*/
{
}
return tempUrl;
}
/**
* Returns registration done page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @param metaAlias hosted provider's meta alias
* @return registration done page URL.
*/
{
}
return tempUrl;
}
/**
* Returns logout done page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @param metaAlias hosted provider's meta alias
* @return logout done page URL.
*/
{
}
return tempUrl;
}
/**
* Returns federation done page URL.
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @param metaAlias hosted provider's meta alias
* @return federation done page URL.
*/
{
}
return tempUrl;
}
/**
* Returns do federate page URL.
*
* @param request <code>HttpServletRequest</code> object
* @param hostedConfig hosted provider's extended meta
* @return do federate page URL.
*/
{
}
return tempUrl;
}
/**
* Returns default page URL.
*
* @param request HTTP Servlet Request.
* @param pageName the page name whose url to be retrieved
* @return String the Page URL.
*/
public static String getDefaultPageURL(
{
}
/**
* Appends meta alias to the URL.
* @param url string url
* @param metaAlias meta alias to be appended
* @return the url with meta alias added
*/
{
return url;
} else {
} else {
}
}
}
/**
* Finds approriate assertion consumer service URL.
* @param spDescriptor sevice provider's meta descriptor
* @param id requested assertion consumer service url id. It could be
* <code>null</code>.
* @return assertion consumer server URL.
*/
public static String getAssertionConsumerServiceURL(
{
if (spDescriptor == null) {
return null;
}
return curValue;
}
if (curUrl.isIsDefault()) {
}
}
}
}
if (defaultValue != null) {
return defaultValue;
} else {
return first;
}
}
/**
* Returns the first profile from the list.
* @param profiles list of profiles
* @return the first profile of the list
*/
return retVal;
}
}
/**
* Returns service provider's authentication context mappings.
* @param hostConfig hosted provider' setended meta
* @return authentication context mapping
*/
if (hostConfig == null) {
return null;
}
try {
} catch (FSException fe) {
"FSServiceUtils.getSPAuthContextInfo: wrong mapping:" +
}
}
}
return retMap;
}
/**
* Determines if the registration profile is SOAP or not.
* @param userID id of the user subject to registration
* @param remoteEntityId remote provider's entity ID
* @param remoteDescriptor remote provider's meta descriptor
* @param metaAlias hosted provider's meta alias
* @param hostedDescriptor hosted provider's meta descriptor
* @return <code>true</code> if the registration profile is SOAP;
* <code>false</code> otherwise.
*/
public static boolean isRegisProfileSOAP(
{
try {
} catch (FSAccountMgmtException e) {
}
return true;
}
"\nremote profile is " + remoteProfile);
}
{
return true;
} else if (hostedProfile.equalsIgnoreCase(
{
return false;
} else {
"Invalid registration profile.");
return true;
}
} else {
{
return true;
} else if (remoteProfile.equalsIgnoreCase(
{
return false;
} else {
"Invalid registration profile.");
return true;
}
}
}
/**
* Returns the minor version of supported protocol.
* @param protocolEnum list of supported protocols
* @return minor version of first supported protocol
*/
int ver = 0;
"FSServiceUtils.getMinorVersion:null protocolEnum");
} else {
ver = 0;
ver = 2;
}
}
return ver;
}
public static FederationSPAdapter getSPAdapter(
{
if (hostSPConfig == null) {
return null;
}
try {
}
return adapterInstance;
}
} catch (Exception e) {
"FSServiceUtils.getSPAdapter: Unable to get provider", e);
}
return null;
}
}