4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * The contents of this file are subject to the terms
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * of the Common Development and Distribution License
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * (the License). You may not use this file except in
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * compliance with the License.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * You can obtain a copy of the License at
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * See the License for the specific language governing
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * permission and limitations under the License.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * When distributing Covered Code, include this CDDL
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Header Notice in each file and include the License file
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * If applicable, add the following below the CDDL Header,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * with the fields enclosed by brackets [] replaced by
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * your own identifying information:
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * "Portions Copyrighted [year] [name of copyright owner]"
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * $Id: CreateHostedIDP.java,v 1.9 2008/06/25 05:50:01 qcheng Exp $
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fosterimport com.sun.identity.saml2.common.SAML2Constants;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fosterimport com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fosterimport com.sun.identity.saml2.jaxb.entityconfig.IDPSSOConfigElement;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fosterimport com.sun.identity.saml2.meta.SAML2MetaException;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fosterimport com.sun.identity.saml2.meta.SAML2MetaManager;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Fosterimport com.sun.identity.saml2.meta.SAML2MetaUtils;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Creates Hosted Identity Provider.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Creates hosted identity provider.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * @param locale Locale of the Request
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * @param params Map of creation parameters.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster public String execute(Locale locale, Map params)
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String metadataFile = getString(params, ParameterKeys.P_META_DATA);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell boolean hasMetaData = (metadataFile != null) &&
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster extendedData = getContent(extendedDataFile, locale);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String entityId = getString(params, ParameterKeys.P_ENTITY_ID);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell String metaAlias = generateMetaAliasForIDP(getString(params,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster map.put(MetaTemplateParameters.P_IDP, metaAlias);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell map.put(MetaTemplateParameters.P_IDP_E_CERT,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster getString(params, ParameterKeys.P_IDP_E_CERT));
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell map.put(MetaTemplateParameters.P_IDP_S_CERT,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster getString(params, ParameterKeys.P_IDP_S_CERT));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster buildMetaDataTemplate(entityId, map, getRequestURL(params));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster extendedData = CreateSAML2HostedProviderTemplate.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String[] results = ImportSAML2MetaData.importData(
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String cot = getString(params, ParameterKeys.P_COT);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster AddProviderToCOT.addToCOT(realm, cot, entityId);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster List attrMapping = getAttributeMapping(params);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster SAML2MetaManager manager = new SAML2MetaManager();
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster Map attribConfig = SAML2MetaUtils.getAttributes(ssoConfig);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster List mappedAttributes = (List)attribConfig.get(
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster return getMessage("idp.configured", locale) + "|||realm=" + realm +
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster "&entityId=" + URLEncoder.encode(entityId, "UTF-8");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String metadata = getString(params, ParameterKeys.P_META_DATA);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell String extendedData = getString(params, ParameterKeys.P_EXTENDED_DATA);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster boolean hasExtendedData = (extendedData != null) &&
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster throw new WorkflowException("both-meta-extended-data-required",
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster params.containsKey(ParameterKeys.P_META_DATA) &&
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell params.containsKey(ParameterKeys.P_EXTENDED_DATA) &&
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster throw new WorkflowException("both-meta-extended-data-required",
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String cotname = getString(params, ParameterKeys.P_COT);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if ((cotname == null) || (cotname.trim().length() == 0)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster throw new WorkflowException("missing-cot", null);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String realm = getString(params, ParameterKeys.P_REALM);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if ((realm == null) || (realm.trim().length() == 0)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster throw new WorkflowException("missing-realm", null);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String entityId = getString(params, ParameterKeys.P_ENTITY_ID);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if ((entityId == null) || (entityId.trim().length() == 0)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster throw new WorkflowException("missing-entity-id", null);