CreateRemoteSP.java revision 4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1c
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/**
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The contents of this file are subject to the terms
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * of the Common Development and Distribution License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * (the License). You may not use this file except in
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * compliance with the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You can obtain a copy of the License at
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * opensso/legal/CDDLv1.0.txt
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * See the License for the specific language governing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * permission and limitations under the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * When distributing Covered Code, include this CDDL
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Header Notice in each file and include the License file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * at opensso/legal/CDDLv1.0.txt.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * If applicable, add the following below the CDDL Header,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * with the fields enclosed by brackets [] replaced by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * your own identifying information:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * $Id: CreateRemoteSP.java,v 1.9 2009/04/09 06:53:43 asyhuang Exp $
f948ca04a28ccfeed9633bf4b0fb0d2c59c37478David Luna *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpackage com.sun.identity.workflow;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.cot.COTException;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.common.SAML2Constants;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.jaxb.entityconfig.AttributeType;
f948ca04a28ccfeed9633bf4b0fb0d2c59c37478David Lunaimport com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.jaxb.entityconfig.ObjectFactory;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.jaxb.entityconfig.SPSSOConfigElement;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement;
import com.sun.identity.saml2.meta.SAML2MetaException;
import com.sun.identity.saml2.meta.SAML2MetaManager;
import com.sun.identity.saml2.meta.SAML2MetaUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.xml.bind.JAXBException;
/**
* Creates Remote Service Provider.
*/
public class CreateRemoteSP
extends Task {
public CreateRemoteSP() {
}
/**
* Creates remote service provider.
*
* @param locale Locale of the request.
* @param params Map of creation parameters.
*/
public String execute(Locale locale, Map params)
throws WorkflowException {
validateParameters(params);
String realm = getString(params, ParameterKeys.P_REALM);
String metadataFile = getString(params, ParameterKeys.P_META_DATA);
String metadata = getContent(metadataFile, locale);
String extendedMeta = null;
List attrMapping = getAttributeMapping(params);
if (!attrMapping.isEmpty()) {
try {
EntityDescriptorElement e =
ImportSAML2MetaData.getEntityDescriptorElement(metadata);
String eId = e.getEntityID();
extendedMeta =
createExtendedDataTemplate(
eId, false);
} catch (SAML2MetaException ex) {
throw new WorkflowException(ex.getMessage());
} catch (JAXBException ex) {
throw new WorkflowException(ex.getMessage());
}
}
String[] results = ImportSAML2MetaData.importData(
realm, metadata, extendedMeta);
String entityId = results[1];
String cot = getString(params, ParameterKeys.P_COT);
if ((cot != null) && (cot.length() > 0)) {
try {
AddProviderToCOT.addToCOT(realm, cot, entityId);
} catch (COTException e) {
throw new WorkflowException(e.getMessage());
}
}
try {
if (!attrMapping.isEmpty()) {
SAML2MetaManager manager = new SAML2MetaManager();
EntityConfigElement config =
manager.getEntityConfig(realm, entityId);
SPSSOConfigElement ssoConfig =
manager.getSPSSOConfig(realm, entityId);
if (ssoConfig != null) {
ObjectFactory objFactory = new ObjectFactory();
AttributeType avp = objFactory.createAttributeElement();
String key = SAML2Constants.ATTRIBUTE_MAP;
avp.setName(key);
avp.getValue().addAll(attrMapping);
ssoConfig.getAttribute().add(avp);
}
manager.setEntityConfig(realm, config);
}
} catch (SAML2MetaException e) {
throw new WorkflowException(e.getMessage());
} catch (JAXBException e) {
throw new WorkflowException(e.getMessage());
}
return getMessage("sp.configured", locale);
}
private void validateParameters(Map params)
throws WorkflowException {
String metadata = getString(params, ParameterKeys.P_META_DATA);
if ((metadata == null) || (metadata.trim().length() == 0)) {
throw new WorkflowException("meta-data-required", null);
}
String realm = getString(params, ParameterKeys.P_REALM);
if ((realm == null) || (realm.trim().length() == 0)) {
throw new WorkflowException("missing-realm", null);
}
}
private String createExtendedDataTemplate(
String entityID,
boolean hosted) {
StringBuffer buff = new StringBuffer();
String strHosted = (hosted) ? "1" : "0";
buff.append(
"<EntityConfig xmlns=\"urn:sun:fm:SAML:2.0:entityconfig\"\n" +
" xmlns:fm=\"urn:sun:fm:SAML:2.0:entityconfig\"\n" +
" hosted=\"" + strHosted + "\"\n" +
" entityID=\"" + entityID + "\">\n\n" +
" <SPSSOConfig>\n" +
" </SPSSOConfig>\n" +
"</EntityConfig>\n");
return buff.toString();
}
}