0

我在我的应用程序中使用这个LDAP 类。我的本地主机上有 Apache DS,它工作正常。

在我的应用程序中,我已成功连接到 LDAP 服务器:

  conn.connect("localhost", 10389);
  conn.bind(LDAPConnection.LDAP_V3, "uid=admin,ou=system","secret".getBytes("UTF8"));

然后我尝试在 LDAP 目录中搜索一些数据:

  attrList = new String[]{"dn", "cn", "mail"};
  sFilter = "(mail=admin@test.com)";

  LDAPSearchConstraints cons = new LDAPSearchConstraints();
  cons.setDereference(LDAPSearchConstraints.DEREF_ALWAYS);
  LDAPSearchResults searchResults = conn.search("uid=admin,ou=system", LDAPConnection.SCOPE_SUB, sFilter, attrList, false,cons);

并且在 searchResults 中没有结果。那你能帮帮我吗?但是当我在 Apache DS Studio 中使用 SAME PARAMETERS 进行用户搜索时,我可以看到一些结果。请检查此屏幕截图

4

1 回答 1

0

我使用这样的代码:

Attributes matchAttrs = new BasicAttributes(true);
matchAttrs.put(new BasiAttribute("mail", "admin@test.com"));
NamingEnumeration<SearchResult> answer = ctx.search(context, matchAttrs);

wherectx是 type InitialDirContext,并且context是搜索根(上下文)。

于 2013-11-22T14:36:58.043 回答