【发布时间】:2018-05-25 18:16:15
【问题描述】:
我正在开发一个 django 应用程序并尝试使用 django_python3_ldap 连接到我公司的 LDAP 和 AD。我按照settings.py 中的文档基本设置进行操作,但是当我尝试执行python manage.py ldap_sync_users 时,出现此错误
LDAP connect failed: ('unable to open socket', [(datetime.datetime(2018, 5, 25, 12, 25, 36, 77877), <class 'ldap3.core.exceptions.LDAPSocketOpenError'>, LDAPSocketOpenError('socket connection error while opening: [WinError 10061] No connection could be made bec
ause the target machine actively refused it',), ('::1', 389, 0, 0)), (datetime.datetime(2018, 5, 25, 12, 25, 37, 78809), <class 'ldap3.core.exceptions.LDAPSocketOpenError'>, LDAPSocketOpenError('socket connection error while opening: [WinError 10061] No connect
ion could be made because the target machine actively refused it',), ('127.0.0.1', 389))])
CommandError: Could not connect to LDAP server
这是我的 settings.py 文件
import os
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, NestedActiveDirectoryGroupType
# Baseline configuration.
AUTH_LDAP_SERVER_URI = "ldap://***.**.***.**"
LDAP_AUTH_CONNECTION_USERNAME = 'usr@ab.com'
LDAP_AUTH_CONNECTION_PASSWORD = '*******'
# The LDAP search base for looking up users.
LDAP_AUTH_SEARCH_BASE = "ou=people,dc=example,dc=com"
# The LDAP class that represents a user.
LDAP_AUTH_OBJECT_CLASS = "user"
# Keep ModelBackend around for per-user permissions and maybe a local
# superuser.
AUTHENTICATION_BACKENDS = (
'django_python3_ldap.auth.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
DEBUG = True
LDAP_AUTH_USE_TLS = False
# User model fields mapped to the LDAP
# attributes that represent them.
LDAP_AUTH_USER_FIELDS = {
"username": "sAMAccountName",
"first_name": "givenName",
"last_name": "sn",
"email": "mail",
}
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory_principal"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "ab.com"
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"
但我认为这不是配置问题,因为从我看到的所有 google 帖子和 SO 帖子中,这似乎是公司防火墙阻止了我的访问?或者我使用的LDAP_AUTH_CONNECTION_USERNAME 没有权限?有没有其他方法可以发生这种情况?
【问题讨论】:
标签: python django active-directory ldap