Django LDAP 身份验证失败:SERVER_DOWN
Django LDAP authentication fails: SERVER_DOWN
我正在使用 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
代码)吗?
听起来你想要 AUTH_LDAP_GLOBAL_OPTIONS。
我正在使用 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
代码)吗?
听起来你想要 AUTH_LDAP_GLOBAL_OPTIONS。