From 30273925a9cd0da65e289ef79c9116a40a3c9abf Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 25 Apr 2007 04:19:06 +0000
Subject: [PATCH] Update the config file handler so that it will reject any modification which attempts to change the structural object class for an entry.
---
opends/src/server/org/opends/server/messages/ConfigMessages.java | 14 +++++++
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/ConfigFileHandlerTestCase.java | 82 +++++++++++++++++++++++++++++++++++++++++
opends/src/server/org/opends/server/extensions/ConfigFileHandler.java | 11 +++++
3 files changed, 107 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java b/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
index 584d5b0..2e50169 100644
--- a/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
+++ b/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
@@ -1408,6 +1408,17 @@
}
+ // If the structural class is different between the current entry and the
+ // new entry, then reject the change.
+ if (! currentEntry.getEntry().getStructuralObjectClass().equals(
+ entry.getStructuralObjectClass()))
+ {
+ int msgID = MSGID_CONFIG_FILE_MODIFY_STRUCTURAL_CHANGE_NOT_ALLOWED;
+ String message = getMessage(msgID, String.valueOf(entryDN));
+ throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
+ }
+
+
// Create a new config entry to use for the validation testing.
ConfigEntry newEntry = new ConfigEntry(e, currentEntry.getParent());
diff --git a/opends/src/server/org/opends/server/messages/ConfigMessages.java b/opends/src/server/org/opends/server/messages/ConfigMessages.java
index a497236..428cd2d 100644
--- a/opends/src/server/org/opends/server/messages/ConfigMessages.java
+++ b/opends/src/server/org/opends/server/messages/ConfigMessages.java
@@ -6573,6 +6573,17 @@
/**
+ * The message ID for the message that will be used if a an attempt is made to
+ * modify an entry in the config backend in a manner that will change its
+ * structural object class.
+ */
+ public static final int
+ MSGID_CONFIG_FILE_MODIFY_STRUCTURAL_CHANGE_NOT_ALLOWED =
+ CATEGORY_MASK_CONFIG | SEVERITY_MASK_MILD_ERROR | 653;
+
+
+
+ /**
* Associates a set of generic messages with the message IDs defined in this
* class.
*/
@@ -6845,6 +6856,9 @@
registerMessage(MSGID_CONFIG_FILE_MODIFY_NO_SUCH_ENTRY,
"Entry %s cannot be modified because the specified entry " +
"does not exist");
+ registerMessage(MSGID_CONFIG_FILE_MODIFY_STRUCTURAL_CHANGE_NOT_ALLOWED,
+ "Configuration entry %s cannot be modified because the " +
+ "change would alter its structural object class");
registerMessage(MSGID_CONFIG_FILE_MODIFY_REJECTED_BY_CHANGE_LISTENER,
"Entry %s cannot be modified because one of the " +
"configuration change listeners registered for that " +
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/ConfigFileHandlerTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/ConfigFileHandlerTestCase.java
new file mode 100644
index 0000000..394836d
--- /dev/null
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/ConfigFileHandlerTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Portions Copyright 2007 Sun Microsystems, Inc.
+ */
+package org.opends.server.extensions;
+
+
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.opends.server.TestCaseUtils;
+
+import static org.testng.Assert.*;
+
+
+
+/**
+ * A set of test cases for the config file handler.
+ */
+public class ConfigFileHandlerTestCase
+ extends ExtensionsTestCase
+{
+ /**
+ * Makes sure that the server is running before performing any tests.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @BeforeClass()
+ public void setUp()
+ throws Exception
+ {
+ TestCaseUtils.startServer();
+ }
+
+
+
+ /**
+ * Tests to verify that attempts to change the structural object class of a
+ * config entry will be rejected.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test
+ public void testChangingStructuralClass()
+ throws Exception
+ {
+ int resultCode = TestCaseUtils.applyModifications(
+ "dn: cn=config",
+ "changetype: modify",
+ "replace: objectClass",
+ "objectClass: top",
+ "objectClass: device",
+ "objectClass: extensibleObject"
+ );
+
+ assertFalse(resultCode == 0);
+ }
+}
+
--
Gitblit v1.10.0