我正在尝试根据我们的LDAP构建用户身份验证:
settings.py:
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_LDAP_SERVER_URI = "ldap://********-dc01.*******.ru"
import ldap
from django_auth_ldap.config import LDAPSearch
AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=users,dc=*********,dc=ru",ldap.SCOPE_SUBTREE,"(uid=%(user)s)")
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)views.py:
@login_required
def project_list(request):
...urls.py:
(r'^accounts/login/$', 'django.contrib.auth.views.login',{'template_name':'login.html'}),模板是from this example。
它将把我带到auth表单,并得到以下调试输出:
search_s('cn=users,dc=********,dc=ru', 2, '(uid=bolotnov)') raised OPERATIONS_ERROR({'info': '000004DC: LdapErr: DSID-0C0906DC, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db0', 'desc': 'Operations error'},)
search_s('cn=users,dc=**********,dc=ru', 2, '(uid=bolotnov)') raised OPERATIONS_ERROR({'info': '000004DC: LdapErr: DSID-0C0906DC, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db0', 'desc': 'Operations error'},)
Authentication failed for bolotnov
Authentication failed for bolotnov我试着用谷歌搜索,但没有找到任何可以帮助我更进一步的东西,也许是来自社区的提示-也许是我遗漏了什么简单的东西,或者是有一个检查要做?我似乎可以通过Softerra ldap浏览器匿名绑定到我们的LDAP,也许ldap_auth_user_search应该有所不同?
发布于 2012-02-17 03:31:43
尽管ldap_simple_bind_s()会返回一个成功的绑定,但我必须禁用引用选项才能使其正常工作:
ldap.set_option(ldap.OPT_REFERRALS, 0)发布于 2012-02-14 08:54:29
您需要绑定到服务器,即使是匿名绑定。
因此,您必须具有
AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""发布于 2015-04-21 18:04:43
我不知道我是否可以在这篇文章中问另一个问题。在views.py中,我有类似这样的东西:
默认登录(请求):
C= {} c.update(csrf(request)) return render_to_response('login.html',c)
def auth_view(请求):
username = request.POST.get('username','') password = request.POST.get('password','') user = auth.authenticate(username=username,password=password)
如果user不是None: auth.login(request,user) return HttpResponseRedirect('/loggedin') else: return HttpResponseRedirect('/invalid')
我的问题是如何将其与ldap服务器绑定?在django文档中有用于日志记录的模板:
导入日志记录
logger = logging.getLogger('django_auth_ldap') logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG)
但我不知道如何在rhis代码中实现它
https://stackoverflow.com/questions/9261848
复制相似问题