我对 LDAP 有以下配置,如果我使用ldap.SCOPE_SUBTREE
,它会显示:
ldap3.SCOPE_SUBTREE, "(uid=%(user)s)")
AttributeError: 'module' object has no attribute 'SCOPE_SUBTREE'
如果我使用 ldap3.SUBTREE - 出现的错误:
File "C:\Python34\lib\site-packages\django_auth_ldap-1.2.13-py3.4.eg\django_auth_ldap\config.py", line 65, in get_ldap
ImportError: No module named 'ldap.filter' in
[LDAP-Error.docx](https://github.com/cannatag/ldap3/files/1280858/LDAP-Error.docx)
代码:
#Specify User Profile Model if profile needs to be populated (Optional)
#AUTH_PROFILE_MODULE = 'account.UserProfile'
#Baseline configuration.
AUTH_LDAP_SERVER_URI = "ldap://server ip"
AUTH_LDAP_BIND_DN = "user@example.com"
AUTH_LDAP_BIND_PASSWORD = "xxxxxxxxxx"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
ldap3.SUBTREE, "(uid=%(user)s)")
#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com"
# Set up the basic group parameters.
#AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=users,dc=example",
# ldap3.SUBTREE,"(objectClass=posixGroup)"
#)
#LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"
#AUTH_LDAP_GROUP_TYPE = PosixGroupType()
#group = PUN-GLOBALSUPPORT
# Simple group restrictions
#AUTH_LDAP_REQUIRE_GROUP = "cn=enabled,ou=django,ou=groups,dc=example,dc=com"
#AUTH_LDAP_DENY_GROUP = "cn=disabled,ou=django,ou=groups,dc=example,dc=com"
#Populate the Django user from the LDAP directory.
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTH_LDAP_PROFILE_ATTR_MAP = {
"employee_number": "employeeNumber"
}
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "cn=active,ou=groups,dc=PUN",
"is_staff": "cn=staff,ou=groups,dc=PUN",
"is_superuser": "cn=superuser,ou=groups,dc=PUN"
}
AUTH_LDAP_PROFILE_FLAGS_BY_GROUP = {
"is_awesome": ["cn=awesome,ou=groups,dc=PUN"]
}
#AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=PUN",
# ldap.SCOPE_SUBTREE, "(cn=%(user)s)")
# This is the default, but I like to be explicit.
AUTH_LDAP_ALWAYS_UPDATE_USER = True
# Use LDAP group membership to calculate group permissions.
#AUTH_LDAP_FIND_GROUP_PERMS = True
# Cache group memberships for an hour to minimize LDAP traffic
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
# Keep ModelBackend around for per-user permissions and maybe a local
#Configuration for LDAP
# superuser.
AUTHENTICATION_BACKENDS = (
'django_python3_ldap.auth.LDAPBackend',
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
#Enable Logging method 1
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"loggers": {
"django_python3_ldap": {
"handlers": ["console"],
"level": "INFO",
},
},
}
##Enable Logging method 2. Enable debug for ldap server connection
#logger = logging.getLogger('django_auth_ldap')
#logger.addHandler(logging.StreamHandler())
#logger.setLevel(logging.DEBUG)