如何使用NET::LDAP ruby中的person实体从LDAP获取用户的所有组



我在ruby中使用Net::LDAP来获取个人实体信息,如cn、department,但我也想要用户所属的列表组,我尝试使用memberof属性,但它只返回一个组下面给出的例子,但我是多组的成员

{:cn=>"Garg, Puja",
:title=>"Developer",
:mail=>"Puja@abc.com",
:samaccountname=>"pujagarg",
:memberof=>"CN=DEVELOPER TEAM,OU=Distribution Groups,OU=_Global,OU=ABC,DC=int,DC=abc,DC=com"}

解决方案1:memberOf(在AD中(存储为distinguishedNames列表。你的过滤器需要像这样:

(&(objectCategory=user)(memberOf=cn=MyCustomGroup,ou=ouOfGroup,dc=subdomain,dc=domain,dc=com))

如果你还没有可分辨的名称,你可以用搜索

(&(objectCategory=group)(cn=myCustomGroup))

示例:

filter = "(&(objectClass=user)(sAMAccountName=#{username})(memberof=CN=group-name,OU=Linux Groups,OU=Linux))"

此示例列出了用户所属的所有组。

更多详细信息请参阅此线程

解决方案2:使用现代ldapsearch命令行工具的示例:

ldapsearch --port 1389 --baseDn 'ou=people,dc=example,dc=com' 
--sizeLimit 3 --searchScope one --bindDn 'cn=directory manager' 
--bindPasswordFile ~/.pwdFile '(uid=user.0)' isMemberOf
dn: uid=user.0,ou=people,dc=example,dc=com
isMemberOf: cn=Dynamic Home Directories,ou=groups,dc=example,dc=com
isMemberOf: cn=bellevue,ou=groups,dc=example,dc=com
isMemberOf: cn=shadow entries,ou=groups,dc=example,dc=com
isMemberOf: cn=persons,ou=groups,dc=example,dc=com

此搜索响应表明user.0是所列组的成员。以上是从LDAP透视图。

有关更多详细信息,请参阅此链接。

最新更新