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

Matthew Swift
04.18.2016 8d16f1ef80784676d9ab34cb12b6954da96d3276
OPENDJ-2738 DN validation fails when RDN uses a custom attribute

SchemaBuilder.java:

* In addSchema0(), do not call addAttributeType(), but
buildAttributeType() like for Syntax and MatchingRule

SchemaBuilderTestCase.java:

* Added a non regression test
2 files modified
65 ■■■■■ changed files
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java 44 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java 21 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
@@ -1189,13 +1189,7 @@
     * @return A builder to continue building the MatchingRule.
     */
    public MatchingRule.Builder buildMatchingRule(final MatchingRule matchingRule) {
        return buildMatchingRule(matchingRule, true);
    }
    private MatchingRule.Builder buildMatchingRule(final MatchingRule matchingRule, final boolean initialize) {
        if (initialize) {
            lazyInitBuilder();
        }
        lazyInitBuilder();
        return new MatchingRule.Builder(matchingRule, this);
    }
@@ -1255,13 +1249,7 @@
     * @return A builder to continue building the Syntax.
     */
    public Syntax.Builder buildSyntax(final Syntax syntax) {
        return buildSyntax(syntax, true);
    }
    private Syntax.Builder buildSyntax(final Syntax syntax, final boolean initialize) {
        if (initialize) {
            lazyInitBuilder();
        }
        lazyInitBuilder();
        return new Syntax.Builder(syntax, this);
    }
@@ -2346,35 +2334,35 @@
        // unlikely, may be different in the new schema.
        for (final Syntax syntax : schema.getSyntaxes()) {
            buildSyntax(syntax, false).addToSchema(overwrite);
            buildSyntax(syntax).addToSchema(overwrite);
        }
        for (final MatchingRule matchingRule : schema.getMatchingRules()) {
            buildMatchingRule(matchingRule, false).addToSchema(overwrite);
            buildMatchingRule(matchingRule).addToSchema(overwrite);
        }
        for (final MatchingRuleUse matchingRuleUse : schema.getMatchingRuleUses()) {
            addMatchingRuleUse(matchingRuleUse, overwrite);
            buildMatchingRuleUse(matchingRuleUse).addToSchema(overwrite);
        }
        for (final AttributeType attributeType : schema.getAttributeTypes()) {
            addAttributeType(attributeType, overwrite);
            buildAttributeType(attributeType).addToSchema(overwrite);
        }
        for (final ObjectClass objectClass : schema.getObjectClasses()) {
            addObjectClass(objectClass, overwrite);
            buildObjectClass(objectClass).addToSchema(overwrite);
        }
        for (final NameForm nameForm : schema.getNameForms()) {
            addNameForm(nameForm, overwrite);
            buildNameForm(nameForm).addToSchema(overwrite);
        }
        for (final DITContentRule contentRule : schema.getDITContentRules()) {
            addDITContentRule(contentRule, overwrite);
            buildDITContentRule(contentRule).addToSchema(overwrite);
        }
        for (final DITStructureRule structureRule : schema.getDITStuctureRules()) {
            addDITStructureRule(structureRule, overwrite);
            buildDITStructureRule(structureRule).addToSchema(overwrite);
        }
    }
@@ -2421,13 +2409,13 @@
            nameForm2StructureRules = new HashMap<>();
            name2OIDs = new HashMap<>();
            warnings = new LinkedList<>();
        }
        if (copyOnWriteSchema != null) {
            // Copy the schema.
            addSchema0(copyOnWriteSchema, true);
            options = Options.copyOf(copyOnWriteSchema.getOptions());
            copyOnWriteSchema = null;
            if (copyOnWriteSchema != null) {
                // Copy the schema.
                addSchema0(copyOnWriteSchema, true);
                options = Options.copyOf(copyOnWriteSchema.getOptions());
                copyOnWriteSchema = null;
            }
        }
    }
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java
@@ -27,6 +27,7 @@
import java.util.ArrayList;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.Connection;
@@ -2137,4 +2138,24 @@
            .as("Expected the enum ordering matching rule to be removed at the same time as the enum syntax")
            .hasSize(coreSchema.getMatchingRules().size());
    }
    @Test
    public void attributeTypesUseNewlyBuiltSyntaxes() throws Exception {
        final Schema coreSchema = Schema.getCoreSchema();
        final Schema schema = new SchemaBuilder(coreSchema)
                .addAttributeType("( 1.2.3.4.5.7 NAME 'associateoid'  "
                                          + "EQUALITY 2.5.13.2 ORDERING 2.5.13.3 SUBSTR 2.5.13.4 "
                                          + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE userApplications "
                                          + "X-APPROX '1.3.6.1.4.1.26027.1.4.1' )", false)
                .toSchema();
        Syntax dnSyntax = schema.getAttributeType("distinguishedName").getSyntax();
        assertThat(dnSyntax).isSameAs(schema.getSyntax("1.3.6.1.4.1.1466.115.121.1.12"));
        LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder();
        boolean isValid = dnSyntax.valueIsAcceptable(ByteString.valueOfUtf8("associateoid=test"), invalidReason);
        assertThat(isValid)
                .as("Value should have been valid, but it is not: " + invalidReason.toString())
                .isTrue();
    }
}