简体   繁体   English

Java LDAP查询以检索组织单位中的所有用户

[英]Java LDAP query to retrieve all users in an organisational unit

I cannot find a way to get users from LDAP by specific organisational unit. 我找不到按特定组织单位从LDAP获取用户的方法。 Only able to get all users with: 仅能使所有用户拥有:

List users = (List<User>) ldapTemplate.search(base, "(&(objectClass=person))", new UserAttributesMapper());

If I add to query something like (memberOf=OU=Users) I get empty results. 如果我添加类似(memberOf = OU = Users)之类的查询,则会得到空结果。 What is the correct query for this kind of action? 这种动作的正确查询是什么?

Probably you have wrong LDAP path. 可能您的LDAP路径错误。 Download**LDAP Browser** and check the path under which your users are; 下载** LDAP浏览器**,并检查用户所在的路径; then use this exact path in your query. 然后在查询中使用此确切路径。

If the OU is a sub tree, use that as the base of the search. 如果OU是子树,则将其用作搜索的基础。 If it's an attribute, search on 如果是属性,请搜索

(&(objectClass=person)(ou=Users))

Your 'memberOf' search should also work if the memberOf attribute is maintained and up to date, but you need to specify the full DN of Users, not juste RDN. 如果memberOf属性得到了维护并且是最新的,那么您的'memberOf'搜索也应该起作用,但是您需要指定用户的完整DN,而不仅仅是RDN。

Actually, you can only use the (ou=Users) filter, if the ou attribute is part of the person entries (which is hardly the case). 实际上,如果ou属性是人员条目的一部分,则只能使用(ou = Users)过滤器(实际上并非如此)。

You could use ou=Users,dc=Company,dc=com as the base. 您可以使用ou = Users,dc = Company,dc = com作为基础。

Otherwise, LDAP standard defines a way to match an assertion as part of the Distinguished Name, but unfortunately not all LDAP servers support that. 否则,LDAP标准定义了一种将断言作为专有名称的一部分进行匹配的方法,但不幸的是,并非所有的LDAP服务器都支持该断言。 OpenDJ, Sun Directory Server and RH DS do support it, probably some other ones. OpenDJ,Sun Directory Server和RH DS确实支持它,可能还有其他一些支持。 The filter you should use is the following: 您应该使用以下过滤器:

(&(objectclass=person)(ou:dn:=users)) (&(对象类=人)(OU:DN:=用户))

Regards, 问候,

Ludovic. 朱利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM