【问题标题】:How to get the user belongs to which group in python如何获取用户属于python中的哪个组
【发布时间】:2019-09-18 12:43:46
【问题描述】:

我想根据活动目录名称获取用户的 AD 组。 我使用过 ldap3 模块,但它并没有解决无效凭证的问题,尽管我输入了正确的

 conn = Connection(Server('<AD server name>', port=389, use_ssl=False),
               auto_bind=AUTO_BIND_NO_TLS, user='<username>',
               password='<password>')

错误:ldap3.core.exceptions.LDAPBindError:自动绑定不成功 - invalidCredentials

【问题讨论】:

  • 你能用你试过的代码和你得到的确切错误信息更新你的问题吗?

标签: python python-3.x active-directory ldap


【解决方案1】:

您可以尝试使用 NTLM 身份验证。

这对我有用:

from ldap3 import Server, Connection, NTLM

server = Server("in.domain.com")
with Connection(server, user="{}\\{}".format("MYDOMAIN", "your_username"), password="your_password", authentication=NTLM) as conn:
    conn.search("dc=in,dc=domain,dc=com", "(&(sAMAccountName={}))".format("user_you_want_to_find"),
                attributes=['memberOf'])
    entry = conn.entries

for group in entry[0]['memberOf']:
    print(group)

脚本应该打印user_you_want_to_find 所属的每个组的通用名称...

问候。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多