Django LDAP身份验证失败:SERVER_DOWN

时间:2015-06-12 19:01:10

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

我使用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代码)?

1 个答案:

答案 0 :(得分:3)

听起来像你想要AUTH_LDAP_GLOBAL_OPTIONS

相关问题