mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
28.58.2016 a5e647d27af7f67741546d95eade2595a08b22cd
OPENDJ-2956 Issue warnings during schema validation of a DIT content rule if it references obsolete elements
4 files modified
94 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java 29 ●●●● patch | view | raw | blame | history
opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java 51 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java 4 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DITContentRule.java
@@ -18,7 +18,6 @@
import static com.forgerock.opendj.ldap.CoreMessages.*;
import static java.util.Arrays.*;
import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
import java.util.Collection;
@@ -784,6 +783,9 @@
                                        .getObjectClassType().toString());
                warnings.add(message);
            }
            if (!isObsolete() && structuralClass.isObsolete()) {
                warnings.add(WARN_DIT_CR_HAS_OBSOLETE_STRUCTURAL_CLASS.get(getNameOrOID(), structuralClassOID));
            }
        }
        if (!auxiliaryClassOIDs.isEmpty()) {
@@ -806,23 +808,29 @@
                                            .toString());
                    throw new SchemaException(message);
                }
                if (!isObsolete() && objectClass.isObsolete()) {
                    warnings.add(WARN_DIT_CR_HAS_OBSOLETE_AUXILIARY_CLASS.get(getNameOrOID(), oid));
                }
                auxiliaryClasses.add(objectClass);
            }
        }
        if (!requiredAttributeOIDs.isEmpty()) {
            requiredAttributes =
                getAttributeTypes(schema, requiredAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_REQUIRED_ATTR1);
                getAttributeTypes(schema, requiredAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_REQUIRED_ATTR1,
                        warnings, WARN_DIT_CR_HAS_OBSOLETE_REQUIRED_ATTR);
        }
        if (!optionalAttributeOIDs.isEmpty()) {
            optionalAttributes =
                getAttributeTypes(schema, optionalAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_OPTIONAL_ATTR1);
                getAttributeTypes(schema, optionalAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_OPTIONAL_ATTR1,
                        warnings, WARN_DIT_CR_HAS_OBSOLETE_OPTIONAL_ATTR);
        }
        if (!prohibitedAttributeOIDs.isEmpty()) {
            prohibitedAttributes =
                getAttributeTypes(schema, prohibitedAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_PROHIBITED_ATTR1);
                getAttributeTypes(schema, prohibitedAttributeOIDs, ERR_ATTR_SYNTAX_DCR_UNKNOWN_PROHIBITED_ATTR1,
                        warnings, WARN_DIT_CR_HAS_OBSOLETE_PROHIBITED_ATTR);
        }
        // Make sure that none of the prohibited attributes is required by
@@ -851,16 +859,23 @@
        requiredAttributes = Collections.unmodifiableSet(requiredAttributes);
    }
    private Set<AttributeType> getAttributeTypes(final Schema schema, Set<String> oids, Arg2<Object, Object> errorMsg)
    private Set<AttributeType> getAttributeTypes(final Schema schema, Set<String> oids,
            Arg2<Object, Object> unkwownElementErrorMsg, final List<LocalizableMessage> warnings,
            Arg2<Object, Object> obsoleteElementWarningMsg)
            throws SchemaException {
        Set<AttributeType> attrTypes = new HashSet<>(oids.size());
        for (final String oid : oids) {
            AttributeType attributeType;
            try {
                attrTypes.add(schema.getAttributeType(oid));
                attributeType = schema.getAttributeType(oid);
                attrTypes.add(attributeType);
            } catch (final UnknownSchemaElementException e) {
                // This isn't good because it means that the DIT content rule
                // requires an attribute type that we don't know anything about.
                throw new SchemaException(errorMsg.get(getNameOrOID(), oid), e);
                throw new SchemaException(unkwownElementErrorMsg.get(getNameOrOID(), oid), e);
            }
            if (!isObsolete() && attributeType.isObsolete()) {
                warnings.add(obsoleteElementWarningMsg.get(getNameOrOID(), oid));
            }
        }
        return attrTypes;
opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
@@ -1639,6 +1639,16 @@
 required attribute type "%s" which is marked as OBSOLETE in the schema
WARN_NAME_FORM_HAS_OBSOLETE_OPTIONAL_ATTR=The name form "%s" specifies the \
 optional attribute type "%s" which is marked as OBSOLETE in the schema
WARN_DIT_CR_HAS_OBSOLETE_STRUCTURAL_CLASS=The DIT content rule "%s" specifies the \
 structural object class "%s" which is marked as OBSOLETE in the schema
WARN_DIT_CR_HAS_OBSOLETE_AUXILIARY_CLASS=The DIT content rule "%s" specifies the \
 auxiliary object class "%s" which is marked as OBSOLETE in the schema
WARN_DIT_CR_HAS_OBSOLETE_REQUIRED_ATTR=The DIT content rule "%s" specifies the \
 required attribute type "%s" which is marked as OBSOLETE in the schema
WARN_DIT_CR_HAS_OBSOLETE_OPTIONAL_ATTR=The DIT content rule "%s" specifies the \
 optional attribute type "%s" which is marked as OBSOLETE in the schema
WARN_DIT_CR_HAS_OBSOLETE_PROHIBITED_ATTR=The DIT content rule "%s" specifies the \
 prohibited attribute type "%s" which is marked as OBSOLETE in the schema
# Labels for generated documentation
DOC_LOCALE_TAG=Code tag: %s
DOC_LOCALE_OID=Collation order object identifier: %s
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -1562,57 +1562,6 @@
      }
    }
    ObjectClass structuralClass = ditContentRule.getStructuralClass();
    // Make sure that the new DIT content rule doesn't reference an obsolete
    // object class or attribute
    if (structuralClass.isObsolete())
    {
      LocalizableMessage message = ERR_SCHEMA_MODIFY_DCR_STRUCTURAL_OC_OBSOLETE.get(
          ditContentRule.getNameOrOID(), structuralClass.getNameOrOID());
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
    }
    for (ObjectClass oc : ditContentRule.getAuxiliaryClasses())
    {
      if (oc.isObsolete())
      {
        LocalizableMessage message = ERR_SCHEMA_MODIFY_DCR_OBSOLETE_AUXILIARY_OC.get(
            ditContentRule.getNameOrOID(), oc.getNameOrOID());
        throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
      }
    }
    for (AttributeType at : ditContentRule.getRequiredAttributes())
    {
      if (at.isObsolete())
      {
        LocalizableMessage message = ERR_SCHEMA_MODIFY_DCR_OBSOLETE_REQUIRED_ATTR.get(
            ditContentRule.getNameOrOID(), at.getNameOrOID());
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
      }
    }
    for (AttributeType at : ditContentRule.getOptionalAttributes())
    {
      if (at.isObsolete())
      {
        LocalizableMessage message = ERR_SCHEMA_MODIFY_DCR_OBSOLETE_OPTIONAL_ATTR.get(
            ditContentRule.getNameOrOID(), at.getNameOrOID());
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
      }
    }
    for (AttributeType at : ditContentRule.getProhibitedAttributes())
    {
      if (at.isObsolete())
      {
        LocalizableMessage message = ERR_SCHEMA_MODIFY_DCR_OBSOLETE_PROHIBITED_ATTR.get(
            ditContentRule.getNameOrOID(), at.getNameOrOID());
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
      }
    }
    // If there is no existing rule, then we're adding a new DIT content rule.
    // Otherwise, we're replacing an existing one.
    if (existingDCR == null)
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -2162,7 +2162,7 @@
    String nameFormName = "testaddnameformwithobsoleteoc";
    assertFalse(DirectoryServer.getSchema().hasNameForm(nameFormName));
    runModify(argsNotPermissive(), ldif, UNWILLING_TO_PERFORM);
    runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION);
    assertFalse(DirectoryServer.getSchema().hasNameForm(nameFormName));
  }
@@ -2811,7 +2811,7 @@
              "AUX testAddDITContentRuleObsoleteAuxOCAuxiliary " +
              "X-ORIGIN 'SchemaBackendTestCase' )");
    runModify(argsNotPermissive(), ldif, UNWILLING_TO_PERFORM);
    runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION);
  }
  /**