Search in sources :

Example 1 with AttributeSchemaImpl

use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.

the class UpgradeUtils method removeAttributesFromSchema.

protected static void removeAttributesFromSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
    if (!(schemaMods.getAttributes().isEmpty())) {
        for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
            removeAttributeSchema(serviceName, null, schemaType, attrs.getName(), adminToken);
        }
    }
    if (schemaMods.hasSubSchema()) {
        for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
            if (!(schema.getValue().getAttributes().isEmpty())) {
                for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
                    ServiceSchema subSchema = null;
                    try {
                        subSchema = serviceSchema.getSubSchema(schema.getKey());
                    } catch (SMSException smse) {
                        debug.error("Unable to remove attributes from schema", smse);
                        throw new UpgradeException(smse);
                    }
                    removeAttributeSchema(subSchema, attrs.getName());
                }
            }
            if (schema.getValue().hasSubSchema()) {
                ServiceSchema ss = null;
                try {
                    ss = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to remove attributes from schema", smse);
                    throw new UpgradeException(smse);
                }
                removeAttributesFromSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
            }
        }
    }
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with AttributeSchemaImpl

use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.

the class UpgradeUtils method modifyAttributesInExistingSchema.

protected static void modifyAttributesInExistingSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
    for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
        modifyAttributeInExistingSchema(serviceName, null, schemaType, attrs.getName(), attrs.getAttributeSchemaNode(), adminToken);
    }
    if (schemaMods.hasSubSchema()) {
        for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
            for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
                ServiceSchema subSchema = null;
                try {
                    subSchema = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to modify attributes in schema", smse);
                    throw new UpgradeException(smse);
                }
                modifyAttributeInExistingSchema(subSchema, attrs.getName(), attrs.getAttributeSchemaNode());
            }
            if (schema.getValue().hasSubSchema()) {
                ServiceSchema ss = null;
                try {
                    ss = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to modify attributes in schema", smse);
                    throw new UpgradeException(smse);
                }
                modifyAttributesInExistingSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
            }
        }
    }
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with AttributeSchemaImpl

use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.

the class UpgradeUtils method addAttributesToSchema.

protected static void addAttributesToSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
    if (!(schemaMods.getAttributes().isEmpty())) {
        for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
            addAttributeToSchema(serviceName, null, schemaType, attrs.getAttributeSchemaNode(), adminToken);
        }
    }
    if (schemaMods.hasSubSchema()) {
        for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
            if (!(schema.getValue().getAttributes().isEmpty())) {
                for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
                    ServiceSchema subSchema = null;
                    try {
                        subSchema = serviceSchema.getSubSchema(schema.getKey());
                    } catch (SMSException smse) {
                        debug.error("Unable to add attributes to schema", smse);
                        throw new UpgradeException(smse);
                    }
                    addAttributeToSchema(subSchema, attrs.getAttributeSchemaNode());
                }
            }
            if (schema.getValue().hasSubSchema()) {
                ServiceSchema ss = null;
                try {
                    ss = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to add attributes to schema", smse);
                    throw new UpgradeException(smse);
                }
                addAttributesToSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
            }
        }
    }
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with AttributeSchemaImpl

use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.

the class UpgradeUtils method addNewSchema.

/**
     * Adds a new Schema to an already existing service.
     *
     * @param serviceName The name of the service that needs to be extended.
     * @param schemaChanges A "container" object holding the details of the new schema.
     * @param adminToken An admin token.
     * @throws UpgradeException If there was an error while trying to add the new schema to the service.
     */
public static void addNewSchema(String serviceName, SchemaUpgradeWrapper schemaChanges, SSOToken adminToken) throws UpgradeException {
    try {
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminToken);
        InputStream schemaStream = ssm.getSchema();
        Document dom = XMLUtils.toDOMDocument(schemaStream, debug);
        NodeList schemaElements = dom.getElementsByTagName("Schema");
        String schemaName = schemaChanges.getNewSchema().getSchemaName();
        debug.message("Adding new " + schemaName + " schema to " + serviceName);
        if (schemaElements.getLength() == 1) {
            Node schemaElement = schemaElements.item(0);
            NodeList schemas = schemaElement.getChildNodes();
            Node newNextSibling = null;
            int idx = SCHEMA_ORDER.indexOf(schemaName);
            for (int i = 0; i < schemas.getLength(); i++) {
                Node node = schemas.item(i);
                int currentIdx = SCHEMA_ORDER.indexOf(node.getNodeName());
                if (currentIdx > idx) {
                    newNextSibling = node;
                    break;
                }
            }
            String xml = "<" + schemaName + "></" + schemaName + ">";
            Document doc = XMLUtils.toDOMDocument(xml, debug);
            for (AttributeSchemaImpl attr : schemaChanges.getNewSchema().getAttributes()) {
                Node imported = doc.importNode(attr.getAttributeSchemaNode(), true);
                doc.getDocumentElement().appendChild(imported);
            }
            Node schemaNode = dom.importNode(doc.getDocumentElement(), true);
            schemaElement.insertBefore(schemaNode, newNextSibling);
            InputStream is = new ByteArrayInputStream(XMLUtils.print(dom.getDocumentElement()).getBytes());
            ssm.replaceSchema(is);
        } else {
            debug.error("Unexpected number of Schema element in service XML for " + serviceName + "\n" + XMLUtils.print(dom));
            throw new UpgradeException("Unexpected number of Schema element in service XML for " + serviceName);
        }
    } catch (Exception ex) {
        UpgradeProgress.reportEnd("upgrade.failed");
        debug.error("An error occurred while trying to add new schema to service: " + serviceName, ex);
        throw new UpgradeException(ex);
    }
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ByteString(org.forgerock.opendj.ldap.ByteString) Document(org.w3c.dom.Document) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Example 5 with AttributeSchemaImpl

use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.

the class SessionServiceHelper method addNewAttribute.

@Override
public AttributeSchemaImpl addNewAttribute(Set<AttributeSchemaImpl> existingAttrs, AttributeSchemaImpl newAttr) throws UpgradeException {
    if (newAttr.getName().equals(SESSION_CONSTRAINT_HANDLER_ATTR)) {
        for (AttributeSchemaImpl attr : existingAttrs) {
            if (attr.getName().equals(SESSION_CONSTRAINT_HANDLER_OLD_ATTR)) {
                Set<String> defaultValues = attr.getDefaultValues();
                Set<String> newDefaultValues = new HashSet<String>();
                if (destroyAllSessionsSet() && defaultValues.contains(DESTROY_OLD_SESSION)) {
                    newDefaultValues.add(DESTROY_ALL_SESSIONS_CLASS);
                    newAttr = updateDefaultValues(newAttr, newDefaultValues);
                } else if (defaultValues.contains(DENY_ACCESS)) {
                    newDefaultValues.add(NEW_DENY_ACCESS);
                    newAttr = updateDefaultValues(newAttr, newDefaultValues);
                } else if (destroyOldestSessionSet()) {
                    newDefaultValues.add(DESTROY_OLDEST_SESSION_CLASS);
                    newAttr = updateDefaultValues(newAttr, newDefaultValues);
                }
                break;
            }
        }
    } else if (REDUCED_CROSSTALK_ENABLED.equals(newAttr.getName())) {
        updateDefaultValues(newAttr, asSet("false"));
    }
    return newAttr;
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) HashSet(java.util.HashSet)

Aggregations

AttributeSchemaImpl (com.sun.identity.sm.AttributeSchemaImpl)5 SMSException (com.sun.identity.sm.SMSException)4 ByteString (org.forgerock.opendj.ldap.ByteString)4 ServiceSchema (com.sun.identity.sm.ServiceSchema)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AMException (com.iplanet.am.sdk.AMException)1 SSOException (com.iplanet.sso.SSOException)1 InvalidAuthContextException (com.sun.identity.authentication.internal.InvalidAuthContextException)1 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)1 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)1 PolicyException (com.sun.identity.policy.PolicyException)1 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 LoginException (javax.security.auth.login.LoginException)1