【问题标题】:Unable to connect to ldap using django-python3-ldap无法使用 django-python3-ldap 连接到 ldap
【发布时间】:2017-07-24 21:15:30
【问题描述】:

我正在开发 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

这是我的 来自 setting.py 文件的 ldap 连接的 django 配置:

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

请告知如何解决这个问题。

【问题讨论】:

标签: python django python-3.x openldap ldap3


【解决方案1】:

我遇到了同样的问题,请尝试更改以下内容:

从这里

LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_openldap"

到这里:

LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory"

【讨论】:

    【解决方案2】:

    我也遇到过同样的问题。以下更改解决了我的问题

    LDAP_AUTH_CONNECTION_USERNAME = "cn=admin,dc=myldap,dc=com"
    LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory" 
    

    【讨论】:

      猜你喜欢
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      相关资源
      最近更新 更多