【问题标题】:Using django-auth-ldap with Active Directory (Authentication failed to map the username to a DN)将 django-auth-ldap 与 Active Directory 一起使用(身份验证无法将用户名映射到 DN)
【发布时间】:2016-05-04 16:19:04
【问题描述】:

我正在尝试使用 django-auth-ldap 通过我的 Active Directory 对 Django 中的用户进行身份验证,但没有成功。

我的活动目录有以下树:

  • DC=测试,DC=本地
    • CN=用户
      • CN=管理员
      • CN=测试

我有(在 settings.py 中):

AUTH_LDAP_SERVER_URI = "ldap://something.test.local"

AUTH_LDAP_BIND_DN = "cn=Administrator,cn=Users,dc=test,dc=local"
AUTH_LDAP_BIND_PASSWORD = "password"
AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=Users,dc=test,dc=local",
ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

我总是得到(在 Django shell 中调试):

>>> from django.contrib.auth import authenticate, login
>>> authenticate(username='test', password='password')
search_s('cn=Users,dc=test,dc=local', 2, '(uid=%(user)s)') returned 0 objects:
Authentication failed for test: failed to map the username to a DN.

【问题讨论】:

    标签: python django active-directory ldap


    【解决方案1】:

    哪里有:

    AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=Users,dc=test,dc=local",
    ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
    

    应该是:

    AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=Users,dc=test,dc=local",
    ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")
    

    因为在 Active Directory 中字段 uid 通常为空,所以搜索不会返回伪装的用户。

    不知道:

    search_s('cn=Users,dc=test,dc=local', 2, '(uid=%(user)s)') returned 1 objects: cn=test,cn=users,dc=test,dc=local
    Created Django user test
    Populating Django user test
    <User: test>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多