4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster The contents of this file are subject to the terms
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster of the Common Development and Distribution License
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster (the License). You may not use this file except in
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster compliance with the License.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster You can obtain a copy of the License at
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster https://opensso.dev.java.net/public/CDDLv1.0.html or
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster See the License for the specific language governing
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster permission and limitations under the License.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster When distributing Covered Code, include this CDDL
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Header Notice in each file and include the License file
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster If applicable, add the following below the CDDL Header,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster with the fields enclosed by brackets [] replaced by
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster your own identifying information:
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "Portions Copyrighted [year] [name of copyright owner]"
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster $Id: util.jspf,v 1.1 2008/11/25 23:50:41 exu Exp $
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Portions Copyrighted 2011 ForgeRock AS
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<%@ page language="java"
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.federation.meta.IDFFMetaManager,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.federation.meta.IDFFMetaUtils,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.multiprotocol.SingleLogoutManager,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.plugin.session.SessionException,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.plugin.session.SessionProvider,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.plugin.session.SessionManager,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.shared.configuration.SystemPropertiesManager,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.meta.WSFederationMetaManager,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.meta.WSFederationMetaUtils,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster<!-- this code is only intended to work under single user mode -->
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String SAMPLE_COT_NAME = "samplemultiprotocolcot";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String SAMPLE_PREFIX = "multiprotocolsample-";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String IDP_SUFFIX = "-idp";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String SP_SUFFIX = "-sp";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String STATUS = "status";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String SP_BASE_URL = "spBaseUrl";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String PROTOCOL_PARAM_NAME = "spFederationProtocol";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean loggedIn = false;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String redirectUrl = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String localAuthUrl = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String localProto;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String localHost;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String localPort;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String localDeploymentURI;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String defaultRealm = "/";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String baseHost = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String baseURL = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String realBaseURL = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String baseURI = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SSOToken ssoToken = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void createCircleOfTrust(String cotName,String hostedEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String remoteEntityID, String protocol) throws COTException {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Create Circle of Trust
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CircleOfTrustManager cotManager = new CircleOfTrustManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Set cots = cotManager.getAllCirclesOfTrust(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean cotExists = ((cots != null && !cots.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (cotExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Set memberList = cotManager.listCircleOfTrustMember(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster defaultRealm, cotName, protocol);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((memberList == null) || memberList.isEmpty() ||
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster !memberList.contains(hostedEntityID)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cotManager.addCircleOfTrustMember(defaultRealm, cotName,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster protocol, hostedEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if ((memberList == null) || memberList.isEmpty() ||
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster !memberList.contains(remoteEntityID)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cotManager.addCircleOfTrustMember(defaultRealm, cotName,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster protocol, remoteEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Set<String> providers = new HashSet<String>();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster providers.add(hostedEntityID + COTConstants.DELIMITER + protocol);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster providers.add(remoteEntityID + COTConstants.DELIMITER + protocol);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cotManager = new CircleOfTrustManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster new CircleOfTrustDescriptor(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cotName, defaultRealm, COTConstants.ACTIVE, "", null, null,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster null, null, providers));
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Create Circle of Trust
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster * Checks if SAML2/IDFF/WSFed service provider have already been
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster * configured in this instance. Throw exception if yes.
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void checkCurrentSPConfiguration(String hostedSPEntitySuffix,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SSOToken ssoToken)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // check SAML2
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String entityID = hostedSPEntitySuffix + SingleLogoutManager.SAML2
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + SP_SUFFIX;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaManager saml2Manager = new SAML2MetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster saml2Manager.getAllHostedServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster throw new Exception("A SAML2 Service Provider " + entityID + " had already been configured in this instance.");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // check ID-FF
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster entityID = hostedSPEntitySuffix + SingleLogoutManager.IDFF
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + SP_SUFFIX;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster IDFFMetaManager idffManager = new IDFFMetaManager(ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster idffManager.getAllHostedServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster spExists = ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster throw new Exception("An ID-FF Service Provider " + entityID + " had already been configured in this instance.");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle WS-Fed
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster entityID = hostedSPEntitySuffix + SingleLogoutManager.WS_FED
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster + SP_SUFFIX;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaManager wsfedMetaManager = new WSFederationMetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.getAllHostedServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster spExists = ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster throw new Exception("A WS-Federation Service Provider " + entityID + " had already been configured in this instance.");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void configureSAML2ServiceProvider(String remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String hostedSPEntityID, HttpServletRequest request) throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster StringOutputWriter outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Map env = new HashMap();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.ARGUMENT_LOCALE, request.getLocale());
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.sun.identity.federation.cli.FederationManager");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "ssoadm");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CommandManager cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster URL url = new URL(remoteIDPEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String proto = url.getProtocol();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String host = url.getHost();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String port = "" + url.getPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = getDeploymentUri(url);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaManager metaManager = new SAML2MetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllHostedServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && spEntityList.contains(hostedSPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx=0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendedStartIdx=0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendedEndIdx = 0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx=0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag=null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", hostedSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--serviceprovider", "/multiprotosaml2sp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster req = new CLIRequest(null, args, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster endEntityDescriptorTag = "</EntityDescriptor>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = metaXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityConfigTag = "</EntityConfig>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendStartIdx = result.indexOf("<EntityConfig ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendEndIdx = result.indexOf(endEntityConfigTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = result.substring(extendStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx + endEntityConfigTag.length() + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster hostedSPEntityID = descriptor.getEntityID();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster EntityConfigElement extendConfigElm = (EntityConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityConfig(defaultRealm, extendConfigElm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllRemoteIdentityProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean idpExists = ((idpEntityList != null
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && idpEntityList.contains(remoteIDPEntityID));
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get IDP meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args2 = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--identityprovider", "/multiprotosaml2idp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster req = new CLIRequest(null, args2, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx = result.indexOf(endEntityDescriptorTag, metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = result.substring(metaStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx + endEntityDescriptorTag.length() +1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String idpMetaXML = metaXML.replaceAll(realBaseURL,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster proto + "://"+ host + ":" + port + deploymenturi);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster EntityDescriptorElement idpDescriptor = (EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaUtils.convertStringToJAXB(idpMetaXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteIDPEntityID = idpDescriptor.getEntityID();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, idpDescriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Create Circle of Trust
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster createCircleOfTrust(SAMPLE_COT_NAME,hostedSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteIDPEntityID, SingleLogoutManager.SAML2);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void configureIDFFServiceProvider(String remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String hostedSPEntityID, HttpServletRequest request) throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster StringOutputWriter outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Map env = new HashMap();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.ARGUMENT_LOCALE, request.getLocale());
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.sun.identity.federation.cli.FederationManager");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "ssoadm");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CommandManager cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster URL url = new URL(remoteIDPEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String proto = url.getProtocol();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String host = url.getHost();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String port = "" + url.getPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = getDeploymentUri(url);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster IDFFMetaManager metaManager = new IDFFMetaManager(ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllHostedServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists = ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && spEntityList.contains(hostedSPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "idff",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", hostedSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--serviceprovider", "/multiprotoidffsp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</EntityDescriptor>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = metaXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityConfigTag = "</EntityConfig>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendStartIdx = result.indexOf("<EntityConfig ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendEndIdx = result.indexOf(endEntityConfigTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = result.substring(extendStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx + endEntityConfigTag.length() + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] modify extended config to set providerHomePageURL
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int exStartIdx = extendedXML.indexOf(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "<Attribute name=\"providerHomePageURL\">");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int exValueIdx = extendedXML.indexOf("<Value>",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster exStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML = extendedXML.substring(0, exValueIdx + 7) +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster baseURL + "/samples/multiprotocol/demo/home.jsp" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] modify extended config to set providerHomePageURL
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendConfigElm = (com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster IDFFMetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityConfig(defaultRealm, extendConfigElm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllRemoteIdentityProviderIDs(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean idpExists = ((idpEntityList != null && !idpEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && idpEntityList.contains(remoteIDPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get IDP meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args2 = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "idff",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--identityprovider", "/multiprotoidffidp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args2, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</EntityDescriptor>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx + endEntityDescriptorTag.length() +1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String idpMetaXML = metaXML.replaceAll(realBaseURL,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster proto + "://"+ host + ":" + port + deploymenturi);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster idpDescriptor = (com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteIDPEntityID = idpDescriptor.getProviderID();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, idpDescriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster createCircleOfTrust(SAMPLE_COT_NAME, remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster hostedSPEntityID, SingleLogoutManager.IDFF);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void configureWSFedServiceProvider(String remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String hostedSPEntityID, HttpServletRequest request) throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster StringOutputWriter outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Map env = new HashMap();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.ARGUMENT_LOCALE, request.getLocale());
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.sun.identity.federation.cli.FederationManager");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "ssoadm");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CommandManager cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster URL url = new URL(remoteIDPEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String proto = url.getProtocol();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String host = url.getHost();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String port = "" + url.getPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = getDeploymentUri(url);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaManager wsfedMetaManager = new WSFederationMetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList = wsfedMetaManager.getAllHostedServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists = ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && spEntityList.contains(hostedSPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "wsfed",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", hostedSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--serviceprovider", "/multiprotowsfedsp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</Federation>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<Federation ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = metaXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityConfigTag = "</FederationConfig>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendStartIdx = result.indexOf("<FederationConfig ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendEndIdx = result.indexOf(endEntityConfigTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = result.substring(extendStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx + endEntityConfigTag.length() + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] modify extended config to set defaultRelayState
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int exStartIdx = extendedXML.indexOf(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "<Attribute name=\"defaultRelayState\">");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int exValueIdx = extendedXML.indexOf("<Value/>",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster exStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML = extendedXML.substring(0, exValueIdx) + "<Value>" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster baseURL + "/samples/multiprotocol/demo/home.jsp</Value>" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] modify extended config to set defaultRelayState
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] modify extended config to set wantAssertionSigned=false
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "<Attribute name=\"wantAssertionSigned\">");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster exValueIdx = extendedXML.indexOf("<Value>true</Value>",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster exStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML = extendedXML.substring(0, exValueIdx) +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "<Value>false</Value>" + extendedXML.substring(exValueIdx + 19);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] modify extended config to set defaultRelayState
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(metaXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createFederation(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendConfigElm = (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createEntityConfig(defaultRealm, extendConfigElm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.getAllRemoteIdentityProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean idpExists = ((idpEntityList != null && !idpEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && idpEntityList.contains(remoteIDPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get IDP meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args2 = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "wsfed",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--identityprovider", "/multiprotowsfedidp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args2, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</Federation>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<Federation ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx + endEntityDescriptorTag.length() +1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String idpMetaXML = metaXML.replaceAll(realBaseURL,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster proto + "://"+ host + ":" + port + deploymenturi);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Construct a dummy IDP metadata with null cotlist
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = "<FederationConfig FederationID=\"" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteIDPEntityID + "\" hosted=\"false\" xmlns=\"urn:sun:fm:wsfederation:1.0:federationconfig\">" + "\n" + " <IDPSSOConfig>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " <Attribute name=\"cotlist\">\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " </Attribute>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " </IDPSSOConfig>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "</FederationConfig>\n";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Construct a dummy IDP metadata
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(idpMetaXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createFederation(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendConfigElm2 = (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createEntityConfig(defaultRealm, extendConfigElm2);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] importing XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster createCircleOfTrust(SAMPLE_COT_NAME, remoteIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster hostedSPEntityID, SingleLogoutManager.WS_FED);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster private String getDeploymentUri(URL url) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = url.getPath();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int loc = deploymenturi.indexOf("/", 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (loc != -1) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster deploymenturi = deploymenturi.substring(0, loc);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster return deploymenturi;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void configureSAML2IdentityProvider(String hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String remoteSPEntityID, HttpServletRequest request) throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster StringOutputWriter outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Map env = new HashMap();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.ARGUMENT_LOCALE, request.getLocale());
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.sun.identity.federation.cli.FederationManager");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "ssoadm");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CommandManager cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster URL url = new URL(remoteSPEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String proto = url.getProtocol();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String host = url.getHost();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String port = "" + url.getPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = getDeploymentUri(url);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaManager metaManager = new SAML2MetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllHostedIdentityProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean idpExists = ((idpEntityList != null &&
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster idpEntityList.contains(hostedIDPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = 0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = 0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag=null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendStartIdx = 0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendEndIdx = 0;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--identityprovider", "/multiprotosaml2idp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster req = new CLIRequest(null, args, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster endEntityDescriptorTag = "</EntityDescriptor>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = metaXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityConfigTag = "</EntityConfig>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx = result.indexOf("<EntityConfig ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx = result.indexOf(endEntityConfigTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = result.substring(extendStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx + endEntityConfigTag.length() + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster EntityDescriptorElement descriptor =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster (EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster EntityConfigElement extendConfigElm = (EntityConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SAML2MetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityConfig(defaultRealm, extendConfigElm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get SP meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllRemoteServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && spEntityList.contains(remoteSPEntityID));
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args2 = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", remoteSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--serviceprovider", "/multiprotosaml2sp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster req = new CLIRequest(null, args2, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String spMetaXML = metaXML.replaceAll(realBaseURL,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster proto + "://"+ host + ":" + port + deploymenturi);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster EntityDescriptorElement spDescriptor =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster (EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteSPEntityID = spDescriptor.getEntityID();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, spDescriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Create Circle of Trust
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster createCircleOfTrust(SAMPLE_COT_NAME, hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteSPEntityID, SingleLogoutManager.SAML2);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void configureIDFFIdentityProvider(String hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String remoteSPEntityID, HttpServletRequest request) throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster StringOutputWriter outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Map env = new HashMap();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.ARGUMENT_LOCALE, request.getLocale());
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.sun.identity.federation.cli.FederationManager");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "ssoadm");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CommandManager cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster URL url = new URL(remoteSPEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String proto = url.getProtocol();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String host = url.getHost();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String port = "" + url.getPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = getDeploymentUri(url);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster IDFFMetaManager metaManager = new IDFFMetaManager(ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllHostedIdentityProviderIDs(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean idpExists = ((idpEntityList != null && !idpEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && idpEntityList.contains(hostedIDPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "idff",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--identityprovider", "/multiprotoidffidp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</EntityDescriptor>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = metaXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityConfigTag = "</EntityConfig>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendStartIdx = result.indexOf("<EntityConfig ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendEndIdx = result.indexOf(endEntityConfigTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = result.substring(extendStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx + endEntityConfigTag.length() + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] modify extended config to set providerHomePageURL
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int exStartIdx = extendedXML.indexOf(
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "<Attribute name=\"providerHomePageURL\">");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int exValueIdx = extendedXML.indexOf("<Value>",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster exStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML = extendedXML.substring(0, exValueIdx + 7) +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster baseURL + "/samples/multiprotocol/demo/home.jsp" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] modify extended config to set providerHomePageURL
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement extendConfigElm = (com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster IDFFMetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityConfig(defaultRealm, extendConfigElm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.getAllRemoteServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists = ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && spEntityList.contains(remoteSPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get SP meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args2 = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "idff",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", remoteSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--serviceprovider", "/multiprotoidffsp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args2, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</EntityDescriptor>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<EntityDescriptor");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String spMetaXML = metaXML.replaceAll(realBaseURL,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster proto + "://"+ host + ":" + port + deploymenturi);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement spDescriptor = (com.sun.identity.liberty.ws.meta.jaxb.EntityDescriptorElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteSPEntityID = spDescriptor.getProviderID();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaManager.createEntityDescriptor(defaultRealm, spDescriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Create Circle of Trust
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster createCircleOfTrust(SAMPLE_COT_NAME, hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteSPEntityID, SingleLogoutManager.IDFF);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Create Circle of Trust
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster public void configureWSFedIdentityProvider(String hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String remoteSPEntityID, HttpServletRequest request) throws Exception {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster StringOutputWriter outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Map env = new HashMap();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.ARGUMENT_LOCALE, request.getLocale());
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "com.sun.identity.federation.cli.FederationManager");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "ssoadm");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CommandManager cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] create an instance of CommandManager
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster URL url = new URL(remoteSPEntityID);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String proto = url.getProtocol();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String host = url.getHost();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String port = "" + url.getPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String deploymenturi = getDeploymentUri(url);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaManager wsfedMetaManager = new WSFederationMetaManager();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List idpEntityList =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.getAllHostedIdentityProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean idpExists = ((idpEntityList != null && !idpEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && idpEntityList.contains(hostedIDPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!idpExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "wsfed",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--identityprovider", "/multiprotowsfedidp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</Federation>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<Federation ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx, metaEndIdx +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaXML = metaXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityConfigTag = "</FederationConfig>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendStartIdx = result.indexOf("<FederationConfig ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int extendEndIdx = result.indexOf(endEntityConfigTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = result.substring(extendStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendEndIdx + endEntityConfigTag.length() + 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // handle LB case
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!realBaseURL.equals(baseURL)) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendedXML.replaceAll(realBaseURL, baseURL);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get extended data XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(metaXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createFederation(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendConfigElm = (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createEntityConfig(defaultRealm, extendConfigElm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster List spEntityList = wsfedMetaManager.getAllRemoteServiceProviderEntities(defaultRealm);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster boolean spExists = ((spEntityList != null && !spEntityList.isEmpty())
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster && spEntityList.contains(remoteSPEntityID)) ;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (!spExists) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Make a call to CLI to get IDP meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String[] args2 = {"create-metadata-templ",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--spec", "wsfed",
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--entityid", remoteSPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "--serviceprovider", "/multiprotowsfedsp"};
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter = new StringOutputWriter();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster outputWriter);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster cmdManager = new CommandManager(env);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster CLIRequest req = new CLIRequest(null, args2, ssoToken);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String result = outputWriter.getMessages();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Make a call to CLI to get the meta data template
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String endEntityDescriptorTag = "</Federation>";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaStartIdx = result.indexOf("<Federation ");
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int metaEndIdx = result.indexOf(endEntityDescriptorTag,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaStartIdx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String metaXML = result.substring(metaStartIdx,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster metaEndIdx + endEntityDescriptorTag.length() +1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Parse the output of CLI to get metadata XML
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String spMetaXML = metaXML.replaceAll(realBaseURL,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster proto + "://"+ host + ":" + port + deploymenturi);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Swap protocol, host, port and deployment URI
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // to form IDP metadata XML and import it
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Construct a dummy IDP metadata with null cotlist
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster String extendedXML = "<FederationConfig FederationID=\"" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteSPEntityID + "\" hosted=\"false\" xmlns=\"urn:sun:fm:wsfederation:1.0:federationconfig\">" + "\n" + " <SPSSOConfig>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " <Attribute name=\"cotlist\">\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " </Attribute>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " <Attribute name=\"wantAssertionSigned\">\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " <Value>false</Value>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " </Attribute>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster " </SPSSOConfig>\n" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster "</FederationConfig>\n";
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] Construct a dummy IDP metadata
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [START] Import these XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster descriptor = (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(spMetaXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createFederation(defaultRealm, descriptor);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster extendConfigElm2 = (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster WSFederationMetaUtils.convertStringToJAXB(extendedXML);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster wsfedMetaManager.createEntityConfig(defaultRealm, extendConfigElm2);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // [END] importing XMLs
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster createCircleOfTrust(SAMPLE_COT_NAME, hostedIDPEntityID,
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster remoteSPEntityID, SingleLogoutManager.WS_FED);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster baseURL = request.getRequestURI().toString();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster int idx = baseURL.indexOf('/', 1);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster localPort = "" + request.getServerPort();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster localDeploymentURI = baseURL.substring(0, idx);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster baseURL = localProto + "://" + localHost +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ":" + localPort + localDeploymentURI;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster realBaseURL =
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SystemPropertiesManager.get(Constants.AM_SERVER_PROTOCOL) + "://" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SystemPropertiesManager.get(Constants.AM_SERVER_HOST) + ":" +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SystemPropertiesManager.get(Constants.AM_SERVER_PORT) +
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SystemPropertiesManager.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SessionProvider provider = SessionManager.getProvider();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster Object sess = provider.getSession(request);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster if (sess != null) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster loggedIn = provider.isValid(sess);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster } catch (SessionException e) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster SSOTokenManager manager = SSOTokenManager.getInstance();
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ssoToken = null;
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster ssoToken = manager.createSSOToken(request);
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster } catch (SSOException se) {
4fe4e4f798a84a46e567f64ceadd3648eb0582d4Allan Foster // do nothing