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

Nicolas Capponi
28.13.2014 aae7a119d2b8daa9b190e7ee532efb18634b04f5
OPENDJ-1585 Remove DN equality matching rule usage to prevent
indirect usage of DN.toNormalizedString() in ReferentialIntegrityPlugin
1 files modified
42 ■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/plugins/ReferentialIntegrityPlugin.java 42 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/plugins/ReferentialIntegrityPlugin.java
@@ -57,7 +57,6 @@
import org.opends.server.admin.std.server.ReferentialIntegrityPluginCfg;
import org.opends.server.api.Backend;
import org.opends.server.api.DirectoryThread;
import org.opends.server.api.MatchingRule;
import org.opends.server.api.ServerShutdownListener;
import org.opends.server.api.plugin.DirectoryServerPlugin;
import org.opends.server.api.plugin.PluginResult;
@@ -335,7 +334,7 @@
      for (DN baseDN : cfgBaseDNs)
      {
        Backend b = DirectoryServer.getBackend(baseDN);
        Backend<?> b = DirectoryServer.getBackend(baseDN);
        if ((b != null) && (!b.isIndexed(type, IndexType.EQUALITY)))
        {
          isAcceptable = false;
@@ -670,11 +669,8 @@
    {
      return DirectoryServer.getPublicNamingContexts().keySet();
    }
    else
    {
      return baseDNs;
    }
  }
  /**
   * Search a base DN using a filter built from the configured attribute
@@ -1232,31 +1228,22 @@
   * @return        The SUCCESS if the integrity is maintained or
   *                CONSTRAINT_VIOLATION otherwise
   */
  private PluginResult.PreOperation isIntegrityMaintained(Attribute attr,
                                                          DN entryDN,
                                                          DN entryBaseDN)
  private PluginResult.PreOperation isIntegrityMaintained(Attribute attr, DN entryDN, DN entryBaseDN)
  {
    final MatchingRule rule = attr.getAttributeType().getEqualityMatchingRule();
    try
    {
      for (ByteString attrVal : attr)
      {
        DN valueEntryDN = DN.decode(rule.normalizeAttributeValue(attrVal));
        DN valueEntryDN = DN.decode(attrVal);
        final Entry valueEntry;
        if (currentConfiguration.getCheckReferencesScopeCriteria()
          == CheckReferencesScopeCriteria.NAMING_CONTEXT)
        if (currentConfiguration.getCheckReferencesScopeCriteria() == CheckReferencesScopeCriteria.NAMING_CONTEXT)
        {
          if (valueEntryDN.matchesBaseAndScope(entryBaseDN,
            SearchScope.SUBORDINATES))
          if (valueEntryDN.matchesBaseAndScope(entryBaseDN, SearchScope.SUBORDINATES))
          {
            return PluginResult.PreOperation.stopProcessing(
                  ResultCode.CONSTRAINT_VIOLATION,
                  ERR_PLUGIN_REFERENT_NAMINGCONTEXT_MISMATCH.get(
                      valueEntryDN, attr.getName(), entryDN)
                );
            return PluginResult.PreOperation.stopProcessing(ResultCode.CONSTRAINT_VIOLATION,
                ERR_PLUGIN_REFERENT_NAMINGCONTEXT_MISMATCH.get(valueEntryDN, attr.getName(), entryDN));
          }
          valueEntry = DirectoryServer.getEntry(valueEntryDN);
        }
        else
@@ -1267,27 +1254,22 @@
        // Verify that the value entry exists in the backend.
        if (valueEntry == null)
        {
          return PluginResult.PreOperation.stopProcessing(
            ResultCode.CONSTRAINT_VIOLATION,
            ERR_PLUGIN_REFERENT_ENTRY_MISSING.get(
                valueEntryDN, attr.getName(), entryDN));
          return PluginResult.PreOperation.stopProcessing(ResultCode.CONSTRAINT_VIOLATION,
            ERR_PLUGIN_REFERENT_ENTRY_MISSING.get(valueEntryDN, attr.getName(), entryDN));
        }
        // Verify that the value entry conforms to the filter.
        SearchFilter filter = attrFiltMap.get(attr.getAttributeType());
        if (filter != null && !filter.matchesEntry(valueEntry))
        {
          return PluginResult.PreOperation.stopProcessing(
            ResultCode.CONSTRAINT_VIOLATION,
            ERR_PLUGIN_REFERENT_FILTER_MISMATCH.get(
                valueEntry.getName(), attr.getName(), entryDN, filter));
          return PluginResult.PreOperation.stopProcessing(ResultCode.CONSTRAINT_VIOLATION,
            ERR_PLUGIN_REFERENT_FILTER_MISMATCH.get(valueEntry.getName(), attr.getName(), entryDN, filter));
        }
      }
    }
    catch (Exception de)
    {
      return PluginResult.PreOperation.stopProcessing(
        ResultCode.OTHER,
      return PluginResult.PreOperation.stopProcessing(ResultCode.OTHER,
        ERR_PLUGIN_REFERENT_EXCEPTION.get(de.getLocalizedMessage()));
    }