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

neil_a_wilson
14.01.2007 d43280075fcbb93992d7316a06be022fd7874b8c
Update the schema and memory backends so that they will properly set the
matched DN field in the response if the backend doesn't have the entry
specified as the search base DN but does have an ancestor for that entry.

OpenDS Issue Number: 1371
4 files modified
100 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java 34 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java 9 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/SchemaBackendTestCase.java 27 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java 30 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java
@@ -551,21 +551,35 @@
    SearchFilter filter = searchOperation.getFilter();
    // Make sure the base entry exists if it's supposed to be in this backend.
    Entry baseEntry = entryMap.get(baseDN);
    if ((baseEntry == null) && handlesEntry(baseDN))
    {
      DN matchedDN = baseDN.getParentDNInSuffix();
      while (matchedDN != null)
      {
        if (entryMap.containsKey(matchedDN))
        {
          break;
        }
        matchedDN = matchedDN.getParentDNInSuffix();
      }
      int    msgID   = MSGID_MEMORYBACKEND_ENTRY_DOESNT_EXIST;
      String message = getMessage(msgID, String.valueOf(baseDN));
      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID,
                                   matchedDN, null);
    }
    // If it's a base-level search, then just get that entry and return it if it
    // matches the filter.
    if (scope == SearchScope.BASE_OBJECT)
    {
      Entry entry = entryMap.get(baseDN);
      if (entry == null)
      if (filter.matchesEntry(baseEntry))
      {
        int    msgID   = MSGID_MEMORYBACKEND_ENTRY_DOESNT_EXIST;
        String message = getMessage(msgID, String.valueOf(baseDN));
        throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
      }
      if (filter.matchesEntry(entry))
      {
        searchOperation.returnEntry(entry, new LinkedList<Control>());
        searchOperation.returnEntry(baseEntry, new LinkedList<Control>());
      }
    }
    else
opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -4078,6 +4078,7 @@
    boolean found = false;
    DN[] dnArray = baseDNs;
    DN matchedDN = null;
    for (DN dn : dnArray)
    {
      if (dn.equals(baseDN))
@@ -4085,6 +4086,11 @@
        found = true;
        break;
      }
      else if (dn.isAncestorOf(baseDN))
      {
        matchedDN = dn;
        break;
      }
    }
    if (! found)
@@ -4093,7 +4099,8 @@
      String message = getMessage(msgID, searchOperation.getConnectionID(),
                                  searchOperation.getOperationID(),
                                  String.valueOf(baseDN));
      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID,
                                   matchedDN, null);
    }
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/backends/SchemaBackendTestCase.java
@@ -429,6 +429,33 @@
  /**
   * Performs a set of searches in the schema backend to ensure that they
   * correctly set the matched DN in the response.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testSearchMatchedDN()
         throws Exception
  {
    InternalClientConnection conn =
         InternalClientConnection.getRootConnection();
    DN baseDN = DN.decode("o=bogus,cn=schema");
    SearchFilter filter =
         SearchFilter.createFilterFromString("(objectClass=*)");
    for (SearchScope scope : SearchScope.values())
    {
      InternalSearchOperation searchOperation =
           conn.processSearch(baseDN, scope, filter);
      assertNotNull(searchOperation.getMatchedDN(),
                    "No matched DN for scope " + scope);
    }
  }
  /**
   * Tests the behavior of the schema backend with regard to the
   * ds-cfg-show-all-attributes configuration.
   *
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
@@ -854,4 +854,34 @@
    List<String> referrals = references.get(0).getReferralURLs();
    assertEquals(referrals.size(), 2);
  }
  @Test
  public void testSearchInternalMatchedDN() throws Exception
  {
    InvocationCounterPlugin.resetAllCounters();
    TestCaseUtils.initializeTestBackend(true);
    InternalClientConnection conn =
         InternalClientConnection.getRootConnection();
    InternalSearchOperation searchOperation =
         new InternalSearchOperation(
              conn,
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("ou=nonexistent,o=test"),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
              Integer.MAX_VALUE,
              false,
              LDAPFilter.decode("(objectclass=*)"),
              null, null);
    searchOperation.run();
    assertEquals(searchOperation.getResultCode(), ResultCode.NO_SUCH_OBJECT);
    assertNotNull(searchOperation.getMatchedDN());
  }
}