8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: PluginSchema.java,v 1.7 2008/12/15 21:30:43 goodearth Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2010-2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The class <code>PluginSchemaImpl</code> provides the interfaces to obtain
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the schema information of a plugin that is configured for a service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Cannot be instantiated
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected PluginSchema(SSOToken token, String serviceName, String version,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String pluginName, String iName, String orgName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster psi = PluginSchemaImpl.getInstance(token, serviceName, version,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new SMSException(IUMSConstants.UMS_BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the name of the plugin schema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return name of the plugin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the interface name implemented by the plugin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return plugin interface name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the java class name that implements the interface
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return class name that implements the interface
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the URL of the jar file, the contains the complete implementation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for the plugin.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return class name that implements the interface
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the URL for the plugin's resource bundle
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return URL of the plugin's resource bundle
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the i18n properties file name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return i18n properties file name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns URL of the view bean for the service
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return URL for view bean
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the URL of the view bean for the plugin.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param url
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the view bean for the plugin.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if an error occurred while trying to perform the operation.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if the single sign on token is invalid or expired.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setPropertiesViewBeanURL(String url) throws SMSException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // FIXME the call to psi.getPropertiesViewBeanURL() needs to be removed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Node pNode = XMLUtils.getRootNode(pluginDoc, SMSUtils.PLUGIN_SCHEMA);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEntry.debug.error("PluginSchema:setPropertiesViewBeanURL "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "Invalid plugin interface name. (or/and) \n"+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new SMSException(IUMSConstants.UMS_BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "sms-invalid-plugin-interfaceschema-name", null));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((Element) pNode).setAttribute(SMSUtils.PROPERTIES_VIEW_BEAN_URL, url);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Set the psi.viewBeanURL after updating the XML document,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // to avoid updating the variable (even for a short
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // duration) if the user does not have permissions.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the i18n key to resource bundle that describes the plugin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return i18n index key to the resource bundle
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the names of the schema attribute defined for the plugin.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return names of schema attributes defined for the plugin
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the schema for an attribute given the name of the attribute,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * defined for this plugin.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return schema for the attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributeSchemaName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * name of the schema attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AttributeSchema getAttributeSchema(String attributeSchemaName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchemaImpl asi = psi.getAttributeSchema(attributeSchemaName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the <code>String</code> represenation of the Plugin schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sb.append("PluginSchema name: ").append(getName()).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster append("\n\tInterface name: ").append(getInterfaceName()).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster append("\n\tClass name: ").append(getClassName()).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster append("\n\tI18N URL: ").append(getI18NJarURL()).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster append("\n\tI18N File name: ").append(getI18NFileName()).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator i = getAttributeSchemaNames().iterator(); i.hasNext();) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sb.append("\n").append(getAttributeSchema((String) i.next()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // --------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Protected methods
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // --------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEntry.debug.error("PluginSchema:validate exception", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void validatePluginSchema() throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new SMSException("plugin-schema: " + pluginName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " No longer valid. Cache has been cleared. Recreate from" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ServiceSchemaManager"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected Document getDocumentCopy() throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected Node getPluginSchemaNode(Document doc) throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster NodeList nodes = doc.getElementsByTagName(SMSUtils.PLUGIN_SCHEMA);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (nodes == null || (nodes.getLength() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Throw an exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new SMSException(IUMSConstants.UMS_BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Search for the plugin schema name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (XMLUtils.getNodeAttributeValue(nodes.item(i), SMSUtils.NAME)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void replacePluginSchema(Document document) throws SSOException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Construct the serialized XML document
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String pSchema = smsSchema.getPluginSchema(pluginName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the cached SMSEntry, save and refresh
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CachedSMSEntry smsEntry = psi.getCachedSMSEntry();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster e.setAttribute(SMSEntry.ATTR_PLUGIN_SCHEMA, attrs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // --------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Protected static method
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // --------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static void createPluginSchema(SSOToken token, Node node,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSSchema smsSchema) throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = XMLUtils.getNodeAttributeValue(node, SMSUtils.NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String interfaceName = XMLUtils.getNodeAttributeValue(node,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String orgName = DNMapper.orgNameToDN(XMLUtils.getNodeAttributeValue(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if the interface name is valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceSchemaManagerImpl ssmi = ServiceSchemaManagerImpl.getInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!ssmi.getPluginInterfaceNames().contains(interfaceName)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new SMSException(IUMSConstants.UMS_BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // create required intermediate nodes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CreateServiceConfig.checkBaseNodesForOrg(token, orgName, smsSchema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .getServiceName(), smsSchema.getServiceVersion());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Construct the DN for the interfaces node
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sb.append("ou=").append(interfaceName).append(",").append(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CreateServiceConfig.PLUGIN_CONFIG_NODE).append("ou=").append(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster smsSchema.getServiceVersion()).append(",").append("ou=")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(smsSchema.getServiceName()).append(",").append(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEntry.SERVICES_RDN).append(",").append(orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CreateServiceConfig.checkAndCreateOrgUnitNode(token, sb.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Construct DN for plugin schema node
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = "ou=" + name + "," + sb.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CachedSMSEntry ce = CachedSMSEntry.getInstance(token, dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (new SMSException("plugin-schema-already-exists",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "plugin-schema-already-exists"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Add object classes and attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster e.addAttribute(SMSEntry.ATTR_OBJECTCLASS, SMSEntry.OC_TOP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster e.addAttribute(SMSEntry.ATTR_OBJECTCLASS, SMSEntry.OC_SERVICE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster e.addAttribute(SMSEntry.ATTR_PLUGIN_SCHEMA, smsSchema