Django中的AD身份验证连接到LDAP服务器,但身份验证失败?

时间:2018-07-16 09:49:53

标签: django ldap django-authentication

我正在尝试使用Django中的LDAPBackend对用户进行身份验证。 我正在使用django-auth-ldap库。 LDAP服务器会拒绝用户名和密码。

我的settings.py文件:

import ldap

import ldap, logging
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion

logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)

AUTH_LDAP_SERVER_URI = "ldap://server1.com ldap://server2.com ldap://server3.com:389"
AUTH_LDAP_BIND_DN = "CN=ABC - DEF,OU=Process IDs,OU=Service Accounts,DC=homeoffice,DC=Company,DC=com"
AUTH_LDAP_BIND_PASSWORD = "myPassword"

AUTH_LDAP_USER_SEARCH = LDAPSearch("CN=ABC - DEF,OU=Process IDs,OU=Service Accounts,DC=homeoffice,DC=Company,DC=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
]

我的views.py文件:

def logon(request):
    if request.method == 'POST':
        form = loginForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = LDAPBackend().authenticate(request, username=username, password=password)
            if user is not None:
                print("Authenicated!")
    else:
        form = loginForm()
    return(render(request, "logon.html", { "form" : form }))

即使用户DN和密码正确,我也遇到以下错误。

search_s('cn=users,cn=gec - walmart labs,cn=zones,ou=unix,dc=homeoffice,dc=wal-mart,dc=com', 2, '(uid=%(user)s)') returned 1 objects: cn=k0a009m@homeoffice.walmart.com,cn=users, cn=gec - walmart labs,cn=zones,ou=unix,dc=homeoffice,dc=wal-mart,dc=com

Authentication failed for k0a009m: user DN/password rejected by LDAP server.

0 个答案:

没有答案