我有一个案例,我必须使用 DirContext 搜索 API 来返回 ldap 搜索的属性。原因是我想要获取的属性是操作属性,如果我没有在搜索命令中专门设置属性名称,它不会返回。
谁能告诉我如何指定搜索范围并同时返回属性?
我没有看到任何 API 允许我这样做。它们要么允许我指定SearchControls,要么指定attributesToReturn,但不能同时指定两者。
search(Name name, Attributes matchingAttributes)
search(Name name, Attributes matchingAttributes, String[] attributesToReturn)
search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons)
search(Name name, String filter, SearchControls cons)
search(String name, Attributes matchingAttributes)
search(String name, Attributes matchingAttributes, String[] attributesToReturn)
search(String name, String filterExpr, Object[] filterArgs, SearchControls cons)
search(String name, String filter, SearchControls cons)
最佳答案
当然,你不能。您需要使用采用“SearchControls”参数的其他重载之一。
编辑:
Can anyone tell me how to specify the search scope and also returning attribute(s) at the same time?
要返回的属性是 SearchControls 的属性。
关于java - 如何为 ldap DirContext.search(...) 指定搜索范围和返回属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19529716/