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

Nicolas Capponi
28.26.2016 7a48c327a34c8f6ba655d4803601d7d71d683eb0
OPENDJ-2956 Issue warnings during schema validation of a matching rule use if it references obsolete elements
5 files modified
50 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleUse.java 14 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java 2 ●●● patch | view | raw | blame | history
opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties 4 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleTestCase.java 10 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java 20 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleUse.java
@@ -17,9 +17,7 @@
package org.forgerock.opendj.ldap.schema;
import static java.util.Arrays.*;
import static org.forgerock.opendj.ldap.schema.SchemaUtils.*;
import static com.forgerock.opendj.ldap.CoreMessages.*;
import java.util.Collection;
@@ -464,7 +462,7 @@
        }
    }
    void validate(final Schema schema) throws SchemaException {
    void validate(final Schema schema, final List<LocalizableMessage> warnings) throws SchemaException {
        try {
            matchingRule = schema.getMatchingRule(oid);
        } catch (final UnknownSchemaElementException e) {
@@ -474,16 +472,24 @@
                    ERR_ATTR_SYNTAX_MRUSE_UNKNOWN_MATCHING_RULE1.get(getNameOrOID(), oid);
            throw new SchemaException(message, e);
        }
        if (!isObsolete() && matchingRule.isObsolete()) {
            warnings.add(WARN_MATCHING_RULE_USE_HAS_OBSOLETE_MATCHING_RULE.get(getNameOrOID(), oid));
        }
        attributes = new HashSet<>(attributeOIDs.size());
        for (final String attribute : attributeOIDs) {
            AttributeType attributeType;
            try {
                attributes.add(schema.getAttributeType(attribute));
                attributeType = schema.getAttributeType(attribute);
                attributes.add(attributeType);
            } catch (final UnknownSchemaElementException e) {
                final LocalizableMessage message =
                        ERR_ATTR_SYNTAX_MRUSE_UNKNOWN_ATTR1.get(getNameOrOID(), attribute);
                throw new SchemaException(message, e);
            }
            if (!isObsolete() && attributeType.isObsolete()) {
                warnings.add(WARN_MATCHING_RULE_USE_HAS_OBSOLETE_ATTR.get(getNameOrOID(), attribute));
            }
        }
        attributes = Collections.unmodifiableSet(attributes);
    }
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
@@ -2704,7 +2704,7 @@
        for (final MatchingRuleUse use : numericOID2MatchingRuleUses.values().toArray(
                new MatchingRuleUse[numericOID2MatchingRuleUses.values().size()])) {
            try {
                use.validate(schema);
                use.validate(schema, warnings);
            } catch (final SchemaException e) {
                removeMatchingRuleUse(use);
                warnings.add(ERR_MRU_VALIDATION_FAIL.get(use.toString(), e.getMessageObject()));
opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
@@ -1653,6 +1653,10 @@
 name form "%s" which is marked as OBSOLETE in the schema
WARN_DIT_SR_HAS_OBSOLETE_SUPERIOR_RULE=The DIT structure rule "%s" specifies the \
 superior rule "%s" which is marked as OBSOLETE in the schema
WARN_MATCHING_RULE_USE_HAS_OBSOLETE_MATCHING_RULE=The matching rule use "%s" \
 specifies the matching rule "%s" which is marked as OBSOLETE in the schema
WARN_MATCHING_RULE_USE_HAS_OBSOLETE_ATTR=The matching rule use "%s" specifies the \
 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-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleTestCase.java
@@ -11,11 +11,11 @@
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2013-2015 ForgeRock AS.
 * Copyright 2013-2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldap.schema;
import static org.fest.assertions.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_AUTH_PASSWORD_EXACT_DESCRIPTION;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_AUTH_PASSWORD_EXACT_NAME;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.EMR_AUTH_PASSWORD_EXACT_OID;
@@ -27,6 +27,7 @@
import java.util.Map;
import java.util.TreeMap;
import org.forgerock.i18n.LocalizableMessage;
import org.testng.annotations.Test;
/**
@@ -472,7 +473,10 @@
        sb.addMatchingRule(definition, true);
        Schema schema = sb.toSchema();
        assertThat(schema.getWarnings()).isEmpty();
        // MR is OBSOLETE so expect warnings in the schema about this
        for (LocalizableMessage warning : schema.getWarnings()) {
            assertThat(warning.toString()).contains("OBSOLETE");
        }
        assertThat(schema.getMatchingRules()).isNotEmpty();
        final MatchingRule mr = schema.getMatchingRule("objectIdentifierMatch");
        assertThat(mr.getOID()).isEqualTo("2.5.13.0");
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -67,7 +67,6 @@
import org.forgerock.opendj.ldap.schema.CoreSchema;
import org.forgerock.opendj.ldap.schema.DITContentRule;
import org.forgerock.opendj.ldap.schema.DITStructureRule;
import org.forgerock.opendj.ldap.schema.MatchingRule;
import org.forgerock.opendj.ldap.schema.MatchingRuleUse;
import org.forgerock.opendj.ldap.schema.NameForm;
import org.forgerock.opendj.ldap.schema.ObjectClass;
@@ -1830,25 +1829,6 @@
      }
    }
    // Obsolete matching rule and attribute types are not checked by the SDK
    MatchingRule matchingRule = matchingRuleUse.getMatchingRule();
    if (matchingRule.isObsolete())
    {
      LocalizableMessage message = ERR_SCHEMA_MODIFY_MRU_OBSOLETE_MR.get(
          matchingRuleUse.getNameOrOID(), matchingRule.getNameOrOID());
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
    }
    for (AttributeType at : matchingRuleUse.getAttributes())
    {
      if (at.isObsolete())
      {
        LocalizableMessage message = ERR_SCHEMA_MODIFY_MRU_OBSOLETE_ATTR.get(
            matchingRuleUse.getNameOrOID(), matchingRule.getNameOrOID());
        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
      }
    }
    // If there is no existing matching rule use, then we're adding a new one.
    // Otherwise, we're replacing an existing matching rule use.
    if (existingMRU == null)