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

dugan
26.01.2007 2f8d8f79932fc7ace3098a3a32fc71a6bee5c134
Change behavior of ds-cfg-unique-attribute-type attribute so that it is required (mandatory).
6 files modified
185 ■■■■ changed files
opends/resource/schema/02-config.ldif 4 ●●●● patch | view | raw | blame | history
opends/src/admin/defn/org/opends/server/admin/std/UniqueAttributePluginConfiguration.xml 6 ●●●● patch | view | raw | blame | history
opends/src/messages/messages/plugin.properties 3 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java 20 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/resource/config-changes.ldif 2 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/plugins/UniqueAttributePluginTestCase.java 150 ●●●● patch | view | raw | blame | history
opends/resource/schema/02-config.ldif
@@ -2215,6 +2215,6 @@
  X-ORIGIN 'OpenDS Directory Server' )
objectClasses: ( 1.3.6.1.4.1.26027.1.2.120
  NAME 'ds-cfg-unique-attribute-plugin' SUP ds-cfg-plugin
  STRUCTURAL
  MAY ( ds-cfg-unique-attribute-type $ ds-cfg-unique-attribute-base-dn )
  STRUCTURAL MUST ds-cfg-unique-attribute-type
  MAY ds-cfg-unique-attribute-base-dn
  X-ORIGIN 'OpenDS Directory Server' )
opends/src/admin/defn/org/opends/server/admin/std/UniqueAttributePluginConfiguration.xml
@@ -57,7 +57,7 @@
    </adm:default-behavior>
  </adm:property-override>
    <adm:property name="unique-attribute-type" mandatory="false"
    <adm:property name="unique-attribute-type" mandatory="true"
                multi-valued="true">
    <adm:synopsis>
      Specifies the attribute type to check for value uniqueness.
@@ -72,12 +72,12 @@
    <adm:default-behavior>
      <adm:alias>
        <adm:synopsis>
          The plugin will bypass unique attribute checking.
          The plugin will not start if at least one of these is not defined.
        </adm:synopsis>
      </adm:alias>
    </adm:default-behavior>
    <adm:syntax>
      <adm:string />
      <adm:attribute-type />
    </adm:syntax>
    <adm:profile name="ldap">
      <ldap:attribute>
opends/src/messages/messages/plugin.properties
@@ -315,3 +315,6 @@
SEVERE_ERR_PLUGIN_UNIQUEATTR_MODDN_NOT_UNIQUE_80=An error occurred while \
 attempting to perform a modify DN operation on entry %s because the proposed \
 changes failed the attribute value uniqueness check
SEVERE_ERR_PLUGIN_REFERINT_INVALID_PLUGIN_TYPE_81=An attempt was made to \
 register the Referential Integrity plugin to be invoked as a %s plugin.  This \
 plugin type is not allowed for this plugin
opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java
@@ -94,14 +94,8 @@
    for(DN baseDN : configuration.getUniqueAttributeBaseDN())
      baseDNs.add(baseDN);
    //Load attribute types if any.
    for(String attributeType : configuration.getUniqueAttributeType()) {
      AttributeType type =
              DirectoryServer.getAttributeType(attributeType.toLowerCase());
      if(type == null)
        type =
           DirectoryServer.getDefaultAttributeType(attributeType.toLowerCase());
      uniqueAttributeTypes.add(type);
    }
    for(AttributeType attributeType : configuration.getUniqueAttributeType())
      uniqueAttributeTypes.add(attributeType);
  }
@@ -147,14 +141,8 @@
    for(DN baseDN : newConfiguration.getUniqueAttributeBaseDN())
      newConfiguredBaseDNs.add(baseDN);
    //Load attribute types from new configuration.
    for(String attributeType : newConfiguration.getUniqueAttributeType()) {
      AttributeType type =
              DirectoryServer.getAttributeType(attributeType.toLowerCase());
      if(type == null)
        type =
           DirectoryServer.getDefaultAttributeType(attributeType.toLowerCase());
      newUniqueattributeTypes.add(type);
    }
    for(AttributeType attributeType : newConfiguration.getUniqueAttributeType())
      newUniqueattributeTypes.add(attributeType);
    //Switch to the new lists and configurations.
    baseDNs = newConfiguredBaseDNs;
    uniqueAttributeTypes = newUniqueattributeTypes;
opends/tests/unit-tests-testng/resource/config-changes.ldif
@@ -307,6 +307,7 @@
ds-cfg-plugin-enabled: true
-
replace: ds-cfg-unique-attribute-type
ds-cfg-unique-attribute-type: oncRpcNumber
dn: cn=Test Unique Attribute,cn=Plugins,cn=config
changeType: add
@@ -319,6 +320,7 @@
ds-cfg-plugin-type: preOperationAdd
ds-cfg-plugin-type: preOperationModify
ds-cfg-plugin-type: preOperationModifyDN
ds-cfg-unique-attribute-type: bootParameter
dn: cn=JKS,cn=Key Manager Providers,cn=config
changetype: modify
opends/tests/unit-tests-testng/src/server/org/opends/server/plugins/UniqueAttributePluginTestCase.java
@@ -86,8 +86,12 @@
   */
  @BeforeMethod
  public void clearConfigEntries() throws Exception {
    deleteAttrsFromEntry(uidConfigDN,dsConfigAttrType, dsConfigBaseDN);
    deleteAttrsFromEntry(testConfigDN,dsConfigAttrType, dsConfigBaseDN);
    deleteAttrsFromEntry(uidConfigDN, dsConfigBaseDN);
    deleteAttrsFromEntry(testConfigDN, dsConfigBaseDN);
    //Put an attribute type there that won't impact the rest of the unit
    //tests.
    replaceAttrInEntry(uidConfigDN, dsConfigAttrType,"oncRpcNumber");
    replaceAttrInEntry(testConfigDN, dsConfigAttrType,"bootParameter");
  }
@@ -126,28 +130,6 @@
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UID Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UID Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "ds-cfg-unique-attribute-type: uid",
        "",
        "dn: cn=mail Unique Attribute,cn=Plugins,cn=config",
@@ -161,7 +143,7 @@
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "ds-cfg-unique-attribute-type: mail",
        "ds-cfg-unique-attribute-type: othermail",
        "ds-cfg-unique-attribute-type: sn",
        "",
        "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
@@ -173,50 +155,41 @@
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "ds-cfg-unique-attribute-type: telephone",
        "ds-cfg-unique-attribute-type: telephoneNumber",
        "ds-cfg-unique-attribute-type: mobile",
        "ds-cfg-unique-attribute-type: fax",
        "ds-cfg-unique-attribute-type: facsimileTelephoneNumber",
        "ds-cfg-unique-attribute-base-dn: dc=example,dc=com",
        "ds-cfg-unique-attribute-base-dn: o=test",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "dn: cn=UID0 Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UID Unique Attribute",
        "cn: UUID0 Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "ds-cfg-unique-attribute-type: uid",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "dn: cn=UID1 Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UUID Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UUID Unique Attribute",
        "cn: UUID1 Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-unique-attribute-type: uid",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "dn: cn=UID2 Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UUID Unique Attribute",
        "cn: UUID2 Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationModifyDN");
        "ds-cfg-plugin-type: preOperationModifyDN",
        "ds-cfg-unique-attribute-type: uid");
  Object[][] array = new Object[entries.size()][1];
  for (int i=0; i < array.length; i++)
  {
@@ -275,6 +248,17 @@
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "",
        "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: UID Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: ldifImport",
        "",
        "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
@@ -305,7 +289,22 @@
        "ds-cfg-unique-attribute-type: mobile",
        "ds-cfg-unique-attribute-type: fax",
        "ds-cfg-unique-attribute-base-dn: dc=example,dc=com",
        "ds-cfg-unique-attribute-base-dn: badDN");
        "ds-cfg-unique-attribute-base-dn: badDN",
        "",
        "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
        "objectClass: top",
        "objectClass: ds-cfg-plugin",
        "objectClass: ds-cfg-unique-attribute-plugin",
        "cn: phone Unique Attribute",
        "ds-cfg-plugin-class: org.opends.server.plugins.UniqueAttributePlugin",
        "ds-cfg-plugin-enabled: true",
        "ds-cfg-plugin-type: preOperationAdd",
        "ds-cfg-plugin-type: preOperationModify",
        "ds-cfg-plugin-type: preOperationModifyDN",
        "ds-cfg-unique-attribute-type: telephone",
        "ds-cfg-unique-attribute-type: mobile",
        "ds-cfg-unique-attribute-type: badattribute",
        "ds-cfg-unique-attribute-base-dn: dc=example,dc=com" );
    Object[][] array = new Object[entries.size()][1];
    for (int i=0; i < array.length; i++)
@@ -358,7 +357,7 @@
     addEntry(e, ResultCode.SUCCESS);
    //Setup uid attribute to be unique. Test using public naming contexts
    //for base DNs.
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"uid");
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"uid");
    //Rename with new rdn, should fail, there is an entry already with that
    //uid value.
    doModDN(DN.decode("uid=3user.3, ou=people, o=test"), RDN.decode("uid=4"),
@@ -369,7 +368,7 @@
                      RDN.decode("sn=xx+uid=4"),
                      false, null, ResultCode.CONSTRAINT_VIOLATION);
    //Now add a base dn to be unique under, so new superior move can be tested.
    addAttrToEntry(uidConfigDN,dsConfigBaseDN,"ou=new people,o=test");
    replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=new people,o=test");
    //Try to move the entry to a new superior.
@@ -395,7 +394,7 @@
   */
  @Test()
  public void testModOperationNameContexts() throws Exception {
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"mail");
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
    LinkedList<Modification> mods = new LinkedList<Modification>();
    addMods(mods,"mail",ModificationType.REPLACE,"userx@test","userxx@test",
           "user1t@test");
@@ -418,10 +417,8 @@
    doMods(mods, DN.decode("uid=1user.1,ou=People,o=test"),
           ResultCode.SUCCESS);
    mods.clear();
    //Remove mail as the unique attribute.
    deleteAttrsFromEntry(uidConfigDN,dsConfigAttrType);
    //Add employeenumber as the unique attribute.
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"employeenumber");
    //Replace employeenumber as the unique attribute.
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"employeenumber");
    addMods(mods,"employeenumber",ModificationType.INCREMENT,"1");
    //Test modify increment extension.
    //Fail because incremented value of employeenumber (2) already exists.
@@ -440,11 +437,11 @@
  @Test()
  public void testDseeCompatAdd() throws Exception {
    //Set up one plugin with mail attribute and a suffix.
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"mail");
    addAttrToEntry(uidConfigDN,dsConfigBaseDN,"ou=People,o=test");
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
    replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=People,o=test");
    //Set up another plugin with the mail attribute and a different suffix.
    addAttrToEntry(testConfigDN,dsConfigAttrType,"mail");
    addAttrToEntry(testConfigDN,dsConfigBaseDN,"ou=People1,o=test");
    replaceAttrInEntry(testConfigDN,dsConfigAttrType,"mail");
    replaceAttrInEntry(testConfigDN,dsConfigBaseDN,"ou=People1,o=test");
    //Add two entries with same mail attribute value into the different
    //base DNs.
    Entry e1 = makeEntry("cn=test user1, ou=People,o=test");
@@ -470,19 +467,17 @@
   */
  @Test()
  public void testAddOperation() throws Exception {
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"mail");
    addAttrToEntry(uidConfigDN,dsConfigBaseDN,"ou=People1,o=test");
    addAttrToEntry(uidConfigDN,dsConfigBaseDN,"ou=People,o=test");
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
    replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=People1,o=test",
                       "ou=People, o=test");
    Entry e = makeEntry("cn=test user, ou=People,o=test");
    addAttribute(e, "mail", "user1t@test");
    //Fail because mail attribute already exists under "ou=people,o=test".
    addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
    delAttribute(e, "mail");
    //Remove mail attribute type from config.
    deleteAttrsFromEntry(uidConfigDN,dsConfigAttrType);
    //Add mobile, pager, telephonenumber to config.
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"mobile",
                  "pager","telephonenumber");
    //Replace mobile, pager, telephonenumber to config.
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mobile",
                       "pager","telephonenumber");
    addAttribute(e, "mobile", "1-999-1234","1-999-5678","1-444-9012");
    addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
    e.setDN(DN.decode("cn=test user, ou=People,o=test"));
@@ -496,9 +491,9 @@
    addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
    //Test two plugin configuration. Add mail attribute to second plugin
    //instance, leave the first instance as it is.
    addAttrToEntry(testConfigDN,dsConfigAttrType,"mail");
    replaceAttrInEntry(testConfigDN,dsConfigAttrType,"mail");
    //Add suffix to second plugin.
    addAttrToEntry(testConfigDN,dsConfigBaseDN,"ou=People,o=test");
    replaceAttrInEntry(testConfigDN,dsConfigBaseDN,"ou=People,o=test");
    delAttribute(e, "pager");
    //Add some values that will pass the first plugin.
    addAttribute(e, "telephonenumber", "2-999-1234","1-999-5678","1-999-9012");
@@ -517,15 +512,14 @@
   */
  @Test()
  public void testAddOperationNameContext() throws Exception {
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"mail");
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
    Entry e = makeEntry("cn=test user, ou=People,o=test");
    addAttribute(e, "mail", "user77x@test");
    //Fail because mail value "user77x@test" is a value under the
    //"dc=example,dc=com" naming context.
    addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
    delAttribute(e, "mail");
    deleteAttrsFromEntry(uidConfigDN,dsConfigAttrType);
    addAttrToEntry(uidConfigDN,dsConfigAttrType,"mobile",
    replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mobile",
                  "pager","telephonenumber");
    addAttribute(e, "mobile", "1-999-1234","1-999-5678","2-777-9012");
    //Fail because "2-777-9012"  is a telephone value under the
@@ -774,6 +768,22 @@
    conn.processModify(dn, mods);
  }
  private void
  replaceAttrInEntry(DN dn, String attrTypeString, String... attrValStrings) {
    LinkedList<Modification> mods = new LinkedList<Modification>();
    LinkedHashSet<AttributeValue> attrValues =
                                            new LinkedHashSet<AttributeValue>();
    AttributeType attrType = getAttrType(attrTypeString);
    for(String valString : attrValStrings)
      attrValues.add(new AttributeValue(attrType, valString));
    Attribute attr = new Attribute(attrType, attrTypeString, attrValues);
    mods.add(new Modification(ModificationType.REPLACE, attr));
    InternalClientConnection conn =
            InternalClientConnection.getRootConnection();
    conn.processModify(dn, mods);
  }
  /**
   * Try to add an entry to the server checking for the expected return
   * code.