【问题标题】:Django LDAP authentication fails: SERVER_DOWNDjango LDAP 身份验证失败:SERVER_DOWN
【发布时间】:2015-06-12 19:01:09
【问题描述】:

我使用django-auth-ldap 进行身份验证。

我遇到以下错误:

Caught LDAPError while authenticating xxx: SERVER_DOWN({'info': '(unknown error code)', 'desc': "Can't contact LDAP server"},)

使用: AUTH_LDAP_CONNECTION_OPTIONS = { ldap.OPT_X_TLS_REQUIRE_CERT : ldap.OPT_X_TLS_NEVER }

setting.py 应该可以解决问题,但没有。

我玩过,似乎必须在创建连接之前设置此选项。 django_auth_ldap/backend.py 设置连接后的选项:

self._connection = self.ldap.initialize(self.settings.SERVER_URI)
for opt, value in self.settings.CONNECTION_OPTIONS.iteritems():
    self._connection.set_option(opt, value)

使用 django shell 我只有在 ldap.OPT_X_TLS_REQUIRE_CERT 提前设置的情况下才能成功:

from django_auth_ldap.backend import LDAPBackend
ldapobj = LDAPBackend()
user = ldapobj.populate_user(username)
# ERROR:
# [12/Jun/2015 14:15:19] WARNING [django_auth_ldap:396] Caught LDAPError while authenticating xxx: SERVER_DOWN({'info': '(unknown error code)', 'desc': "Can't contact LDAP server"},)
if user is None:
    print "1st try failed!"
    ldapobj.ldap.set_option(ldapobj.ldap.OPT_X_TLS_REQUIRE_CERT, ldapobj.ldap.OPT_X_TLS_NEVER)
    user = ldapobj.populate_user(username)
    print user.is_anonymous()

输出:

 # 1st try failed!
 # False

知道我必须做什么(不修改django-auth-ldap 代码)吗?

【问题讨论】:

    标签: python django authentication active-directory django-auth-ldap


    【解决方案1】:

    听起来你想要AUTH_LDAP_GLOBAL_OPTIONS

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 2020-04-14
    • 2015-04-19
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多