From 7ddd4a6c4c2fbce71c8071bca380e5c5402e697c Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 24 Sep 2015 12:05:10 +0000
Subject: [PATCH] OPENDJ-1857 LDIF changerecord parsing should be less case sensitive

---
 opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciEffectiveRights.java                 |   12 ++----
 opendj-server-legacy/src/test/java/org/opends/server/types/TestCommonSchemaElements.java                              |   13 +++---
 opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java                                       |   23 +++++------
 opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java                                  |   36 +++++-------------
 opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java                           |    6 +--
 opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java                       |   11 +++--
 opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java |    5 +-
 opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalAttributeValue.java                 |    6 ++-
 opendj-server-legacy/src/main/java/org/opends/server/types/AttributeDescription.java                                  |    2 
 9 files changed, 46 insertions(+), 68 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciEffectiveRights.java b/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciEffectiveRights.java
index 1a87f12..120dd6f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciEffectiveRights.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciEffectiveRights.java
@@ -407,15 +407,11 @@
       evalInfo.append(rightsString(container, handler, skipCheck, "proxy"));
       addAttrLevelRightsInfo(container, mask, a, retEntry, "proxy");
       //It is possible that only the aclRightsInfo attribute type was requested.
-      //Only add the aclRights information if the aclRights attribute type was
-      //seen.
+      // Only add the aclRights information if the aclRights attribute type was seen.
       if(hasAttrMask(mask, ACL_RIGHTS))  {
-        String typeStr=aclRightsAttributeLevelStr + ";" +
-                a.getNormalizedPrimaryName();
-        AttributeType attributeType = DirectoryServer
-            .getDefaultAttributeType(typeStr);
-        Attribute attr = Attributes.create(attributeType, evalInfo
-            .toString());
+        String typeStr = aclRightsAttributeLevelStr + ";" + a.getNameOrOID();
+        AttributeType attributeType = DirectoryServer.getDefaultAttributeType(typeStr);
+        Attribute attr = Attributes.create(attributeType, evalInfo.toString());
         //It is possible that the user might have specified the same attributes
         //in both the search and the specific attribute part of the control.
         //Only try to add the attribute type if it already hasn't been added.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
index 78bb8c0..f4a8fe0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
@@ -425,7 +425,6 @@
    * possible the original String value is returned.
    *
    * @param   attrName  The attribute name which should be normalized.
-   *
    * @return  The normalized attribute name.
    */
   private static String normalizeAttributeName(String attrName)
@@ -433,10 +432,10 @@
     AttributeType attrType = DirectoryServer.getAttributeType(attrName);
     if (attrType != null)
     {
-      String attrNameNormalized = attrType.getNormalizedPrimaryName();
+      String attrNameNormalized = attrType.getNormalizedPrimaryNameOrOID();
       if (attrNameNormalized != null)
       {
-         attrName = attrNameNormalized;
+        return attrNameNormalized;
       }
     }
     return attrName;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalAttributeValue.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalAttributeValue.java
index 5e583d4..315a364 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalAttributeValue.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalAttributeValue.java
@@ -27,6 +27,7 @@
 package org.opends.server.replication.plugin;
 
 import static org.opends.server.replication.plugin.HistAttrModificationKey.*;
+import static org.opends.server.util.StaticUtils.*;
 
 import java.util.Collections;
 import java.util.LinkedHashSet;
@@ -77,6 +78,7 @@
 class HistoricalAttributeValue
 {
   private final AttributeDescription attrDesc;
+  /** The lowercase attribute string representation. */
   private final String attrString;
   private final ByteString attributeValue;
   private final CSN csn;
@@ -110,12 +112,12 @@
         options.add(optionsToken[index]);
         index ++;
       }
-      attrString = optionsToken[0];
+      attrString = toLowerCase(optionsToken[0]);
     }
     else
     {
       options = Collections.emptySet();
-      attrString = token[0];
+      attrString = toLowerCase(token[0]);
     }
 
     AttributeType attrType;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
index f040273..c9b9ca4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
@@ -27,28 +27,28 @@
 package org.opends.server.tools.tasks;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.ByteString;
 import org.opends.server.backends.task.FailedDependencyAction;
 import org.opends.server.backends.task.Task;
 import org.opends.server.backends.task.TaskState;
-import org.opends.server.types.Entry;
-import org.opends.server.types.AttributeType;
 import org.opends.server.types.Attribute;
-import org.forgerock.opendj.ldap.ByteString;
+import org.opends.server.types.AttributeType;
 import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
 
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
-import java.util.Set;
 import java.util.HashSet;
 import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
+import java.util.Set;
 import java.util.TimeZone;
-import java.util.Date;
-import java.util.Collections;
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
 import java.text.DateFormat;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 
 import static org.opends.server.util.ServerConstants.*;
 
@@ -133,12 +133,11 @@
     // Build a map of non-superior attribute value pairs for display
     Map<AttributeType, List<Attribute>> attrMap = entry.getUserAttributes();
     for (AttributeType type : attrMap.keySet()) {
-      String typeName = type.getNormalizedPrimaryName();
+      String typeName = type.getNameOrOID();
 
       // See if we've handled it already above
       if (!supAttrNames.contains(typeName)) {
-        LocalizableMessage attrTypeName = getAttributeDisplayName(
-                type.getNormalizedPrimaryName());
+        LocalizableMessage attrTypeName = getAttributeDisplayName(typeName);
         List<Attribute> attrList = entry.getUserAttribute(type);
         for (Attribute attr : attrList) {
           for (ByteString av : attr) {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeDescription.java b/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeDescription.java
index 77ecc28..c3f9fe6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeDescription.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeDescription.java
@@ -300,7 +300,7 @@
   public String toString()
   {
     final StringBuilder buffer = new StringBuilder();
-    buffer.append(attributeType.getNormalizedPrimaryName());
+    buffer.append(attributeType.getNameOrOID());
     for (String option : options)
     {
       buffer.append(';');
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
index 073b925..5e915ad 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
@@ -28,8 +28,8 @@
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.LinkedList;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -144,19 +144,17 @@
     this.isObsolete = isObsolete;
 
     // Make sure we have a primary name if possible.
-    if (primaryName == null) {
-      if (names != null && !names.isEmpty()) {
-        this.primaryName = names.iterator().next();
-      } else {
-        this.primaryName = null;
-      }
-    } else {
+    if (primaryName != null) {
       this.primaryName = primaryName;
+    } else if (names != null && !names.isEmpty()) {
+      this.primaryName = names.iterator().next();
+    } else {
+      this.primaryName = null;
     }
-    this.lowerName = toLowerCase(primaryName);
+    this.lowerName = this.primaryName != null ? toLowerCase(this.primaryName) : oid;
 
-    // OPENDJ-1645: oid changes during server bootstrap, so prefer using name if available
-    hashCode = getNameOrOID().hashCode();
+    // OPENDJ-1645: oid changes during server bootstrap, so prefer using lowername if available
+    hashCode = this.lowerName.hashCode();
 
     // Construct the normalized attribute name mapping.
     if (names != null) {
@@ -220,16 +218,6 @@
   }
 
   /**
-   * Retrieve the normalized primary name for this schema definition.
-   *
-   * @return Returns the normalized primary name for this attribute
-   *         type, or <code>null</code> if there is no primary name.
-   */
-  public final String getNormalizedPrimaryName() {
-    return lowerName;
-  }
-
-  /**
    * Retrieves an iterable over the set of normalized names that may
    * be used to reference this schema definition. The normalized form
    * of an attribute name is defined as the user-defined name
@@ -297,11 +285,7 @@
    * @return The name or OID for this schema definition.
    */
   public final String getNormalizedPrimaryNameOrOID() {
-    if (lowerName != null) {
-      return lowerName;
-    }
-    // Guaranteed not to be null.
-    return oid;
+    return lowerName;
   }
 
   /**
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
index aa76922..e42497a 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
@@ -50,9 +50,7 @@
 import static org.opends.server.util.CollectionUtils.*;
 import static org.testng.Assert.*;
 
-/**
- * Tests the Historical class.
- */
+/** Tests the Historical class. */
 @SuppressWarnings("javadoc")
 public class HistoricalTest extends ReplicationTestCase
 {
@@ -332,7 +330,7 @@
   private static void publishModify(ReplicationBroker broker, CSN changeNum,
       DN dn, String entryuuid, AttributeType attrType, String newValue)
   {
-    Attribute attr = Attributes.create(attrType.getNormalizedPrimaryName(), newValue);
+    Attribute attr = Attributes.create(attrType.getNameOrOID(), newValue);
     List<Modification> mods = newArrayList(new Modification(ModificationType.ADD, attr));
     broker.publish(new ModifyMsg(changeNum, dn, mods, entryuuid));
   }
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
index d1484d1..8a611ab 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -26,6 +26,7 @@
  */
 package org.opends.server.replication.plugin;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -53,6 +54,7 @@
 import static org.opends.server.replication.plugin.EntryHistorical.*;
 import static org.opends.server.replication.protocol.OperationContext.*;
 import static org.opends.server.util.CollectionUtils.*;
+import static org.opends.server.util.StaticUtils.*;
 import static org.testng.Assert.*;
 
 /**
@@ -70,8 +72,8 @@
 public class ModifyConflictTest extends ReplicationTestCase
 {
   private static final String ORGANIZATION = "organization";
-  private static final String DISPLAYNAME = "displayname";
-  private static final String EMPLOYEENUMBER = "employeenumber";
+  private static final String DISPLAYNAME = "displayName";
+  private static final String EMPLOYEENUMBER = "employeeNumber";
   private static final String DESCRIPTION = "description";
   private static final String SYNCHIST = "ds-sync-hist";
 
@@ -1195,9 +1197,8 @@
 
   private void assertContainsOnlyValues(Entry entry, String attrName, String... expectedValues)
   {
-    List<Attribute> attrs = entry.getAttribute(attrName);
-    Attribute attr = attrs.get(0);
-    assertEquals(expectedValues.length, attr.size());
+    Attribute attr = entry.getExactAttribute(getAttributeType(toLowerCase(attrName)), Collections.<String> emptySet());
+    assertThat(attr).hasSize(expectedValues.length);
     for (String value : expectedValues)
     {
       attr.contains(ByteString.valueOf(value));
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/TestCommonSchemaElements.java b/opendj-server-legacy/src/test/java/org/opends/server/types/TestCommonSchemaElements.java
index 1a90ae3..14b8a63 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/TestCommonSchemaElements.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/TestCommonSchemaElements.java
@@ -43,7 +43,6 @@
 
 import static org.opends.server.types.CommonSchemaElements.*;
 
-
 /**
  * This class defines a set of tests for the
  * {@link org.opends.server.types.CommonSchemaElements} class and
@@ -624,34 +623,34 @@
 
   /**
    * Check that the
-   * {@link CommonSchemaElements#getNormalizedPrimaryName()} method
+   * {@link CommonSchemaElements#getNormalizedPrimaryNameOrOID()} method
    * returns <code>null</code> when there is no primary name.
    *
    * @throws Exception
    *           If the test failed unexpectedly.
    */
   @Test
-  public final void testGetNormalizedPrimaryNameDefault()
+  public final void testGetNormalizedPrimaryNameOrOIDDefault()
       throws Exception {
     SchemaDefinitionBuilder builder = getBuilder(null, "1.2.3");
     CommonSchemaElements d = builder.getInstance();
-    Assert.assertNull(d.getNormalizedPrimaryName());
+    Assert.assertEquals(d.getNormalizedPrimaryNameOrOID(), "1.2.3");
   }
 
 
 
   /**
    * Check that the
-   * {@link CommonSchemaElements#getNormalizedPrimaryName()} method.
+   * {@link CommonSchemaElements#getNormalizedPrimaryNameOrOID()} method.
    *
    * @throws Exception
    *           If the test failed unexpectedly.
    */
   @Test
-  public final void testGetNormalizedPrimaryName() throws Exception {
+  public final void testGetNormalizedPrimaryNameOrOID() throws Exception {
     SchemaDefinitionBuilder builder = getBuilder("testType", "1.2.3");
     CommonSchemaElements d = builder.getInstance();
-    Assert.assertEquals(d.getNormalizedPrimaryName(), "testtype");
+    Assert.assertEquals(d.getNormalizedPrimaryNameOrOID(), "testtype");
   }
 
 

--
Gitblit v1.10.0