python-2.7 - 如何获取特定用户所属的所有组 - python、Active Directory

标签 python-2.7 active-directory ldap

我正在尝试设置过滤器以获取特定用户所属的所有组。 我目前正在使用 Python

import traceback
import ldap
try:
    l = ldap.open("192.168.1.1")
    .
    .
    .

    l.simple_bind_s(username, password)
                                        #######################################################################
    f_filterStr = '(objectclass=group)' # Would like to modify this, so I'll not have to make the next loop ...
                                        #######################################################################
    # the next command take some seconds 
    results = l.search_s(dn_recs, ldap.SCOPE_SUBTREE, f_filterStr) 
    for i in results:
        if dict == type(i[1]):
            group_name = i[1].get('name')
            if list == type(group_name):
                group_name = group_name[0];
                search_str = "CN=%s," % username_bare
                if -1 != ("%s" %  i[1].get('member')).find (search_str):
                    print "User belong to this group! %s" % group_name

except Exception,e :
    pass # handle as you wish

最佳答案

我认为你把这件事搞得太难了。

没有Python专家,但可以轻松查询Microsoft Active Directory for all groups a user is a member of使用如下过滤器:

(member:1.2.840.113556.1.4.1941:=(CN=UserName,CN=Users,DC=YOURDOMAIN,DC=NET))\

-吉姆

关于python-2.7 - 如何获取特定用户所属的所有组 - python、Active Directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26585153/

上一篇:TFS 标签命令行

下一篇:R:聚类文档

相关文章:

python - 找不到谷歌应用引擎 dev_appserver.py 文件

powershell - 使用 CSV 作为输入清理 AD

c# - 针对 Active Directory 进行身份验证一次算作两次无效登录

c# - 从 AD 获取用户详细信息很慢

java - 如何为内存 LDAP 服务器中的 UnboundID 添加/自定义控件

filter - 在 LDAP 搜索过滤器/查询中使用通配符

python - .lower()

python - Pandas 如何按间隔按列拆分数据帧

python - 如何从文件或列表中读取?

azure - 我想要具有多个范围的访问 token ,包括 http