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
| | |
| | | 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 |
| | |
| | | |
| | | boolean found = false; |
| | | DN[] dnArray = baseDNs; |
| | | DN matchedDN = null; |
| | | for (DN dn : dnArray) |
| | | { |
| | | if (dn.equals(baseDN)) |
| | |
| | | found = true; |
| | | break; |
| | | } |
| | | else if (dn.isAncestorOf(baseDN)) |
| | | { |
| | | matchedDN = dn; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (! found) |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | * |
| | |
| | | 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()); |
| | | } |
| | | } |