From 538a088c3bd6c80c1038def6b36538258dac7002 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 01 Jul 2016 12:53:43 +0000
Subject: [PATCH] OPENDJ-2956 Issue warnings during schema validation of an object class if it references obsolete elements
---
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java | 51 -------------------------
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java | 3 +
opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties | 8 +++
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java | 12 ++++++
4 files changed, 21 insertions(+), 53 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 ab36d1b..aee56ee 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
@@ -886,6 +886,10 @@
return false;
}
+ if (!isObsolete() && superiorClass.isObsolete()) {
+ warnings.add(WARN_OBJECTCLASS_HAS_OBSOLETE_SUPERIOR_CLASS.get(getNameOrOID(), superClassOid));
+ }
+
// Make sure that the inheritance configuration is acceptable.
final ObjectClassType superiorType = superiorClass.getObjectClassType();
final ObjectClassType type = getObjectClassType();
@@ -1015,6 +1019,10 @@
failValidation(invalidSchemaElements, warnings, message);
return false;
}
+ if (!isObsolete() && attributeType.isObsolete()) {
+ warnings.add(WARN_OBJECTCLASS_HAS_OBSOLETE_REQUIRED_ATTR.get(getNameOrOID(),
+ requiredAttribute));
+ }
declaredRequiredAttributes.add(attributeType);
}
if (requiredAttributes == Collections.EMPTY_SET) {
@@ -1039,6 +1047,10 @@
failValidation(invalidSchemaElements, warnings, message);
return false;
}
+ if (!isObsolete() && attributeType.isObsolete()) {
+ warnings.add(WARN_OBJECTCLASS_HAS_OBSOLETE_OPTIONAL_ATTR.get(getNameOrOID(),
+ optionalAttribute));
+ }
declaredOptionalAttributes.add(attributeType);
}
if (optionalAttributes == Collections.EMPTY_SET) {
diff --git a/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties b/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
index f2cf12d..2b6f063 100644
--- a/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
+++ b/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
@@ -1627,7 +1627,13 @@
ERR_TEMPLATE_FILE_INVALID_LEADING_SPACE=Unable to parse line %d ("%s") from the \
template file because the line started with a space but there were no previous \
lines in the entry to which this line could be appended
-
+WARN_OBJECTCLASS_HAS_OBSOLETE_SUPERIOR_CLASS=The object class "%s" specifies the \
+ superior object class "%s" which is marked as OBSOLETE in the schema
+WARN_OBJECTCLASS_HAS_OBSOLETE_REQUIRED_ATTR=The object class "%s" specifies the \
+ required attribute type "%s" which is marked as OBSOLETE in the schema
+WARN_OBJECTCLASS_HAS_OBSOLETE_OPTIONAL_ATTR=The object class "%s" specifies the \
+ optional attribute type "%s" which is marked as OBSOLETE in the schema
+ required 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
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index de3279e..0bd06de 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -1244,57 +1244,6 @@
}
}
- // Make sure that the new objectclass doesn't reference an undefined
- // superior class, or an undefined required or optional attribute type,
- // and that none of them are OBSOLETE.
- for(ObjectClass superiorClass : objectClass.getSuperiorClasses())
- {
- if (! schema.hasObjectClass(superiorClass.getOID()))
- {
- LocalizableMessage message = ERR_SCHEMA_MODIFY_UNDEFINED_SUPERIOR_OBJECTCLASS.get(
- objectClass.getNameOrOID(), superiorClass.getNameOrOID());
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
- }
- else if (superiorClass.isObsolete())
- {
- LocalizableMessage message = ERR_SCHEMA_MODIFY_OBSOLETE_SUPERIOR_OBJECTCLASS.get(
- objectClass.getNameOrOID(), superiorClass.getNameOrOID());
- throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
- }
- }
-
- for (AttributeType at : objectClass.getDeclaredRequiredAttributes())
- {
- if (! schema.hasAttributeType(at.getOID()))
- {
- LocalizableMessage message = ERR_SCHEMA_MODIFY_OC_UNDEFINED_REQUIRED_ATTR.get(
- objectClass.getNameOrOID(), at.getNameOrOID());
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
- }
- else if (at.isObsolete())
- {
- LocalizableMessage message = ERR_SCHEMA_MODIFY_OC_OBSOLETE_REQUIRED_ATTR.get(
- objectClass.getNameOrOID(), at.getNameOrOID());
- throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
- }
- }
-
- for (AttributeType at : objectClass.getDeclaredOptionalAttributes())
- {
- if (! schema.hasAttributeType(at.getOID()))
- {
- LocalizableMessage message = ERR_SCHEMA_MODIFY_OC_UNDEFINED_OPTIONAL_ATTR.get(
- objectClass.getNameOrOID(), at.getNameOrOID());
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
- }
- else if (at.isObsolete())
- {
- LocalizableMessage message = ERR_SCHEMA_MODIFY_OC_OBSOLETE_OPTIONAL_ATTR.get(
- objectClass.getNameOrOID(), at.getNameOrOID());
- throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
- }
- }
-
// If there is no existing class, then we're adding a new objectclass.
// Otherwise, we're replacing an existing one.
if (existingClass.isPlaceHolder())
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
index 29e9ec6..4cddedd 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -1497,7 +1497,8 @@
"SUP testAddOCObsoleteSuperiorSup STRUCTURAL MUST cn " +
"X-ORIGIN 'SchemaBackendTestCase' )");
- runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION);
+ // object class is obsolete so having an obsolete superior is OK
+ runModify(argsNotPermissive(), ldif, SUCCESS);
}
/**
--
Gitblit v1.10.0