ldap - 如何进行 LDAP 查询以仅返回所有级别中具有 OU=Groups 的组?

标签 ldap ldap-query

如果我正在寻找所有,我会得到太多垃圾。

如果我试图缩小基础,我得到的就太少了。

这是一个例子:

CN=A Team,OU=Groups,OU=Americas,DC=example,DC=com
CN=B TEAM,OU=Groups,OU=EMEA,DC=example,DC=com
CN=C Team,OU=Legacy Groups,DC=example,DC=com
CN=D Team,OU=Groups,OU=Bangalore,OU=APAC,DC=example,DC=com
CN=E Team,OU=Common Groups,DC=example,DC=com

我正在寻找一个返回 A B D E(没有 C)的 LDAP filter - 主要逻辑是让我获得所有具有最后一个 OU=GroupsOU=公共(public)组

我当前的搜索正在使用:

 Search base: CN=Users,DC=citrite,DC=net
 Filter: (objectCategory=Group)

最佳答案

首先,在 Microsoft Active Directory 上不可能通过单个搜索来完成此操作,这是因为 AD 不完全兼容 LDAP。

兼容 LDAP 的服务器支持可扩展匹配过滤器,该过滤器提供必要的 过滤。来自 RFC4511 :

If the dnAttributes field is set to TRUE, the match is additionally applied against all the AttributeValueAssertions in an entry's distinguished name, and it evaluates to TRUE if there is at least one attribute or subtype in the distinguished name for which the filter item evaluates to TRUE. The dnAttributes field is present to alleviate the need for multiple versions of generic matching rules (such as word matching), where one applies to entries and another applies to entries and DN attributes as well.

请注意,可扩展匹配过滤技术仅适用于符合 LDAP 标准的服务器, 其中 AD 不是其中之一。

例如,我将以下条目添加到服务器:

dn: ou=legacy groups,o=training
objectClass: top
objectClass: organizationalUnit
ou: legacy groups

dn: ou=common groups,o=training
objectClass: top
objectClass: organizationalUnit
ou: common groups

dn: ou=groups,o=training
objectClass: top
objectClass: organizationalUnit
ou: groups

dn: cn=a,ou=common groups,o=training
objectClass: top
objectClass: groupOfUniqueNames
uniqueMember: uid=user.0,ou=people,o=training
cn: a

dn: cn=b,ou=groups,o=training
objectClass: top
objectClass: groupOfUniqueNames
uniqueMember: uid=user.0,ou=people,o=training
cn: b

dn: cn=c,ou=legacy groups,o=training
objectClass: top
objectClass: groupOfUniqueNames
uniqueMember: uid=user.0,ou=people,o=training
cn: c

添加上述条目后,检查以下搜索中的过滤器:

ldapsearch --propertiesFilePath ds-setup/11389/ldap-connection.properties \
    --baseDN o=training \
    --searchScope sub '(|(ou:dn:=groups)(ou:dn:=common groups))' 1.1

dn: ou=common groups,o=training

dn: cn=a,ou=common groups,o=training

dn: ou=groups,o=training

dn: cn=b,ou=groups,o=training

请注意,会返回 ou=common groupsou=groups 及其下级,但不会返回 ou=legacy groups 和下属。

此示例使用 ldapsearch 命令行工具的现代语法。如果用户是 利用旧版 OpenLDAP 版本的 ldapsearch,命令行工具的参数是 略有不同,但这并不重要。重要的是过滤器。

关于ldap - 如何进行 LDAP 查询以仅返回所有级别中具有 OU=Groups 的组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10035030/

相关文章:

r - 如何使用 R 运行 ldap 查询?

java - Spring-LDAP - 密码比较如何更新失败的密码尝试

java - Spring LDAP 身份验证问题

c# - 缓慢的 AD 组成员查找

ldap - 如何在ldap中获取用户组

active-directory - 如何在 LDAP 上运行范围查询

java - LDAP 与 CAS + Spring 集成

Java - 使用 linux 访问远程 Activity 目录

c# - 解释 ldap 字符串 "LDAP://DC=amrs,DC=win,DC=ml,dc=COM"的部分

ldap - RabbitMQ LDAP 身份验证失败