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

Jean-Noël Rouvignac
11.49.2016 4dc7ce9d0904bffc31a2a82971d46f969e43e3f5
OPENDJ-3010 Extensible ObjectClass should accept all attributes
1 files added
2 files modified
64 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java 11 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EntrySchemaCheckingTestCase.java 17 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java 36 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
@@ -394,6 +394,8 @@
    /** The indicates whether or not validation failed. */
    private boolean isValid;
    /** Whether this is the extensible object class, which allows any attribute types. */
    private boolean isExtensibleObject;
    /**
     * Construct a extensibleObject object class where the set of allowed
@@ -430,6 +432,11 @@
        this.objectClassType = builder.type;
        this.requiredAttributeOIDs = unmodifiableCopyOfSet(builder.requiredAttributes);
        this.optionalAttributeOIDs = unmodifiableCopyOfSet(builder.optionalAttributes);
        this.isExtensibleObject = isExtensible();
    }
    private boolean isExtensible() {
        return hasName(EXTENSIBLE_OBJECT_OBJECTCLASS_NAME) || hasNameOrOID(EXTENSIBLE_OBJECT_OBJECTCLASS_OID);
    }
    /**
@@ -632,7 +639,7 @@
     *         <code>false</code> if not.
     */
    public boolean isOptional(final AttributeType attributeType) {
        return optionalAttributes.contains(attributeType);
        return isExtensibleObject || optionalAttributes.contains(attributeType);
    }
    /**
@@ -646,7 +653,7 @@
     *         <code>false</code> if not.
     */
    public boolean isRequired(final AttributeType attributeType) {
        return requiredAttributes.contains(attributeType);
        return isExtensibleObject || requiredAttributes.contains(attributeType);
    }
    /**
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EntrySchemaCheckingTestCase.java
@@ -29,8 +29,8 @@
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.EntryResolver;
import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.Action;
import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.EntryResolver;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.testng.annotations.Test;
@@ -956,6 +956,21 @@
        assertConformsToSchema(e, defaultPolicy());
    }
    @Test
    public void testExtensibleObjectAcceptsAnyAttribute() throws Exception {
        // @formatter:off
        final Entry e = newEntry(
            "dn: dc=example,dc=com",
            "objectClass: top",
            "objectClass: organization",
            "objectClass: extensibleObject",
            "o: example",
            "dummy: it works too!!");
        // @formatter:on
        assertConformsToSchema(e, defaultPolicy());
    }
    /**
     * Tests schema checking for an entry (not covered by a DIT content rule)
     * with a valid single structural objectclass as well as an auxiliary
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java
New file
@@ -0,0 +1,36 @@
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldap.schema;
import static org.fest.assertions.Assertions.*;
import static org.forgerock.opendj.ldap.schema.Schema.*;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class ObjectClassTestCase extends AbstractSchemaTestCase {
    @Test
    public void extensibleObjectAcceptsAllAttributes() {
        Schema schema = getCoreSchema();
        ObjectClass extensibleObject = schema.getObjectClass(EXTENSIBLE_OBJECT_OBJECTCLASS_OID);
        AttributeType attributeType = schema.getAttributeType("dummy");
        assertThat(attributeType.isPlaceHolder()).isTrue();
        assertThat(extensibleObject.isRequired(attributeType)).isTrue();
        assertThat(extensibleObject.isOptional(attributeType)).isTrue();
        assertThat(extensibleObject.isRequiredOrOptional(attributeType)).isTrue();
    }
}