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

Ludovic Poitou
25.47.2011 ad1e1e776a8f5386df8237af2bc413446c4d8762
opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java
@@ -23,11 +23,13 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.plugins;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.LinkedHashMap;
@@ -220,6 +222,8 @@
      return PluginResult.PreOperation.continueOperationProcessing();
    }
    LinkedList<AttributeValue> recordedValues =
        new LinkedList<AttributeValue>();
    for (AttributeType t : config.getType())
    {
      List<Attribute> attrList = entry.getAttribute(t);
@@ -238,16 +242,24 @@
              if((conflictDN=
                      uniqueAttrValue2Dn.putIfAbsent(v, entry.getDN()))==null)
              {
                recordedValues.add(v);
                conflictDN = getConflictingEntryDN(baseDNs, entry.getDN(),
                                                   config, v);
              }
              if (conflictDN != null)
              {
                // Before returning, we need to remove all values added
                // in the uniqueAttrValue2Dn map, because PostOperation
                // plugin does not get called.
                for (AttributeValue v2 : recordedValues)
                {
                   uniqueAttrValue2Dn.remove(v2);
                }
                Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(
                    t.getNameOrOID(), v.getValue().toString(),
                    conflictDN.toString());
                      t.getNameOrOID(), v.getValue().toString(),
                      conflictDN.toString());
                return PluginResult.PreOperation.stopProcessing(
                    ResultCode.CONSTRAINT_VIOLATION, msg);
                      ResultCode.CONSTRAINT_VIOLATION, msg);
              }
            }
            catch (DirectoryException de)
@@ -261,6 +273,12 @@
                               de.getResultCode().toString(),
                               de.getMessageObject());
             // Try some cleanup before returning, to avoid memory leaks
             for (AttributeValue v2 : recordedValues)
             {
               uniqueAttrValue2Dn.remove(v2);
             }
              return PluginResult.PreOperation.stopProcessing(
                    DirectoryServer.getServerErrorResultCode(), m);
            }
@@ -291,6 +309,8 @@
      return PluginResult.PreOperation.continueOperationProcessing();
    }
    LinkedList<AttributeValue> recordedValues =
        new LinkedList<AttributeValue>();
    for (Modification m : modifyOperation.getModifications())
    {
      Attribute a = m.getAttribute();
@@ -316,12 +336,20 @@
              if((conflictDN=
                      uniqueAttrValue2Dn.putIfAbsent(v, entryDN))==null)
              {
               conflictDN = getConflictingEntryDN(baseDNs, entryDN, config,
                recordedValues.add(v);
                conflictDN = getConflictingEntryDN(baseDNs, entryDN, config,
                                                   v);
              }
              if (conflictDN != null)
              {
                Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(
                // Before returning, we need to remove all values added
                // in the uniqueAttrValue2Dn map, because PostOperation
                // plugin does not get called.
                for (AttributeValue v2 : recordedValues)
                {
                   uniqueAttrValue2Dn.remove(v2);
                }
                 Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(
                    t.getNameOrOID(), v.getValue().toString(),
                    conflictDN.toString());
                return PluginResult.PreOperation.stopProcessing(
@@ -371,11 +399,19 @@
                  if((conflictDN=
                      uniqueAttrValue2Dn.putIfAbsent(v, entryDN))==null)
                  {
                    recordedValues.add(v);
                    conflictDN = getConflictingEntryDN(baseDNs, entryDN,
                                                        config, v);
                  }
                  if (conflictDN != null)
                  {
                    // Before returning, we need to remove all values added
                    // in the uniqueAttrValue2Dn map, because PostOperation
                    // plugin does not get called.
                    for (AttributeValue v2 : recordedValues)
                    {
                      uniqueAttrValue2Dn.remove(v2);
                    }
                    Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(
                        t.getNameOrOID(), v.getValue().toString(),
                        conflictDN.toString());
@@ -394,6 +430,12 @@
                                         de.getResultCode().toString(),
                                         de.getMessageObject());
                  // Try some cleanup before returning, to avoid memory leaks
                  for (AttributeValue v2 : recordedValues)
                  {
                    uniqueAttrValue2Dn.remove(v2);
                  }
                  return PluginResult.PreOperation.stopProcessing(
                      DirectoryServer.getServerErrorResultCode(), message);
                }
@@ -431,6 +473,8 @@
      return PluginResult.PreOperation.continueOperationProcessing();
    }
    LinkedList<AttributeValue> recordedValues =
        new LinkedList<AttributeValue>();
    RDN newRDN = modifyDNOperation.getNewRDN();
    for (int i=0; i < newRDN.getNumValues(); i++)
    {
@@ -451,11 +495,19 @@
        if((conflictDN=uniqueAttrValue2Dn.putIfAbsent(
                              v, modifyDNOperation.getEntryDN()))==null)
        {
          recordedValues.add(v);
          conflictDN = getConflictingEntryDN(baseDNs,
            modifyDNOperation.getEntryDN(), config, v);
        }
        if (conflictDN != null)
        {
          // Before returning, we need to remove all values added
          // in the uniqueAttrValue2Dn map, because PostOperation
          // plugin does not get called.
          for (AttributeValue v2 : recordedValues)
          {
            uniqueAttrValue2Dn.remove(v2);
          }
          Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(
              t.getNameOrOID(), v.getValue().toString(),
              conflictDN.toString());
@@ -474,6 +526,12 @@
                         de.getResultCode().toString(),
                         de.getMessageObject());
        // Try some cleanup before returning, to avoid memory leaks
        for (AttributeValue v2 : recordedValues)
        {
          uniqueAttrValue2Dn.remove(v2);
        }
        return PluginResult.PreOperation.stopProcessing(
            DirectoryServer.getServerErrorResultCode(), m);
      }