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

neil_a_wilson
25.19.2007 30273925a9cd0da65e289ef79c9116a40a3c9abf
Update the config file handler so that it will reject any modification which
attempts to change the structural object class for an entry.

OpenDS Issue Number: 1544
1 files added
2 files modified
107 ■■■■■ changed files
opends/src/server/org/opends/server/extensions/ConfigFileHandler.java 11 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/messages/ConfigMessages.java 14 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/ConfigFileHandlerTestCase.java 82 ●●●●● patch | view | raw | blame | history
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());
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 " +
opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/ConfigFileHandlerTestCase.java
New file
@@ -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);
  }
}