From 4dc7ce9d0904bffc31a2a82971d46f969e43e3f5 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 11 May 2016 08:13:41 +0000
Subject: [PATCH] OPENDJ-3010 Extensible ObjectClass should accept all attributes
---
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java | 36 ++++++++++++++++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EntrySchemaCheckingTestCase.java | 17 ++++++++
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java | 11 ++++-
3 files changed, 61 insertions(+), 3 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
index 350ba45..10eddf3 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
+++ b/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);
}
/**
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EntrySchemaCheckingTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EntrySchemaCheckingTestCase.java
index 5ac5881..5284dc2 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/EntrySchemaCheckingTestCase.java
+++ b/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
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java
new file mode 100644
index 0000000..7607458
--- /dev/null
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/ObjectClassTestCase.java
@@ -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();
+ }
+}
--
Gitblit v1.10.0