UnboundID LDAP Java SDK - 需要列出给定父DN的后代

时间:2014-07-28 10:12:41

标签: ldap unboundid-ldap-sdk

如何使用UnboundID LDAP SDK查询LDAP中父条目的所有后代?

我正在寻找类似过滤器的东西,可以说基于父DN的过滤器。或者某种方式列出给定条目的所有子项。

是否可以使用UnboundID LDAP SDK?我无法找到提及此类操作的示例或文档。

1 个答案:

答案 0 :(得分:3)

确保使用LDAP Search Scope

获取任何容器的后代

在UnboundID中,SearchScope中使用了SearchRequest类并在其示例中显示:

 // Construct a filter that can be used to find everyone in the Sales
 // department, and then create a search request to find all such users
 // in the directory.
 Filter filter = Filter.createEqualityFilter("ou", "Sales");
 SearchRequest searchRequest =
      new SearchRequest("dc=example,dc=com", SearchScope.SUB, filter,
           "cn", "mail");
 SearchResult searchResult;

 try
 {
   searchResult = connection.search(searchRequest);

   for (SearchResultEntry entry : searchResult.getSearchEntries())
   {
     String name = entry.getAttributeValue("cn");
     String mail = entry.getAttributeValue("mail");
   }
 }
 catch (LDAPSearchException lse)
 {
   // The search failed for some reason.
   searchResult = lse.getSearchResult();
   ResultCode resultCode = lse.getResultCode();
   String errorMessageFromServer = lse.getDiagnosticMessage();
 }

-Jim