我正在开发 django 网站,我想在我的应用程序中使用 ldap 身份验证。我正在使用 Django 1.11 通过 django-python3-ldap 进行身份验证。我使用 ldapsearch 测试了到我的 ldap 的连接,它成功了,我得到了以下结果:
ally@websrv:/web/demo_project_ally$ ldapsearch -x -W -D 'cn=admin,dc=myldap,dc=com' -b "dc=myldap,dc=com" "cn=ally ally" -H ldap://myldap.com
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <dc=myldap,dc=com> with scope subtree
# filter: cn=ally ally
# requesting: ALL
#
# ally ally, my_ou, myldap.com
dn: cn=ally ally,ou=my_ou,dc=myldap,dc=com
cn: ally ally
givenName: ally
gidNumber: 500
homeDirectory: /home/users/aally
sn: ally
loginShell: /bin/sh
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
userPassword:: e01ENX1kNVJuSkw0bTV3RzR3PT0=
uidNumber: 1000
uid: aally
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
当我尝试从 django 连接时,我会收到此错误:
System check identified no issues (0 silenced).
July 24, 2017 - 20:40:26
Django version 1.11, using settings 'demo_project.settings'
Starting development server at http://0:8002/
Quit the server with CONTROL-C.
LDAP connect failed: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None
[24/Jul/2017 20:40:37] "POST /accounts/login/ HTTP/1.1" 200 917
错误:
LDAP connect failed: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None
这是我的 django 配置,用于来自 setting.py 文件的 ldap 连接:
LDAP_AUTH_URL = "ldap://myldap.com:389"
LDAP_AUTH_USE_TLS = False
LDAP_AUTH_SEARCH_BASE = "dc=myldap,dc=com"
LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"
LDAP_AUTH_USER_FIELDS = {
"username": "uid",
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
LDAP_AUTH_CLEAN_USER_DATA = "django_python3_ldap.utils.clean_user_data"
LDAP_AUTH_SYNC_USER_RELATIONS = "django_python3_ldap.utils.sync_user_relations"
LDAP_AUTH_FORMAT_SEARCH_FILTERS = "django_python3_ldap.utils.format_search_filters"
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_openldap"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = None
LDAP_AUTH_CONNECTION_USERNAME = "admin"
LDAP_AUTH_CONNECTION_PASSWORD = "password"
#Print information about failed logins to your console by adding the following to your settings.py file.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"loggers": {
"django_python3_ldap": {
"handlers": ["console"],
"level": "INFO",
},
},
}
我在 Ubuntu 16.04 下工作并使用 python3.5
我将此参考用于我的设置: https ://github.com/etianen/django-python3-ldap
我可以使用以下命令执行 LDAP 用户的初始同步:./manage.py ldap_sync_users
请建议如何解决这个问题。