寻找django-auth-ldap包的一些帮助。
背景 - 我正在尝试将LDAP用户添加到默认用户角色STAFF,ACTIVE和SUPERUSER。毫无疑问,您可以从debug.log中看到django-auth-ldap成功找到LDAP用户名并相应地填充DJANGO。
但是,它不会将LDAP用户添加到相关角色,即活动,工作人员,超级用户,因为它表明它不属于相关组,尽管在用户名和组上执行LDAP搜索也是如此。
非常感谢任何帮助/建议。
由于
search_s('ou=xxxx,o=xx,c=uk', 2, '(uid=%(user)s)') returned 1 objects: cn=someusername,ou=xx,ou=xxxxx,ou=xxxx,o=xx,c=uk
Populating Django user someusername
cn=someusername,ou=xxxx,ou=xxx,ou=xxx,o=xx,c=uk is not a member of cn=somegroup,ou=xx,ou=xxx,ou=xxxx,o=xx,c=uk
cn=someusername,ou=xxxx,ou=xxx,ou=xxx,o=xx,c=uk is not a member of cn=somegroup,ou=xx,ou=xxx,ou=xxxx,o=xx,c=uk
cn=someusername,ou=xxxx,ou=xxx,ou=xxx,o=xx,c=uk is not a member of cn=somegroup,ou=xx,ou=xxx,ou=xxxx,o=xx,c=uk
import os
import ldap
import logging
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, PosixGroupType
** Omitted for clarity **
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
LDAP_AUTH_URL = "ldaps://ldap.xxxxxxxxxxx.xx.uk/"
LDAP_AUTH_SEARCH_BASE = "ou=xxxx,o=xx,c=uk"
# Application definition
AUTH_LDAP_GLOBAL_OPTIONS = {
ldap.OPT_X_TLS_REQUIRE_CERT: False,
ldap.OPT_REFERRALS: False,
}
AUTH_LDAP_SERVER_URI = "ldaps://ldap.xxxxxxxxxx.xx.uk"
AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_ALWAYS_UPDATE_USER = True
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=xxxx,o=xx,c=uk", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=xx,ou=xxx,ou=xxxx,o=xx,c=uk",
ldap.SCOPE_SUBTREE, "(objectClass=groupOfNames)"
)
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr="cn")
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_active": "cn=somegroup,ou=xxx,ou=xxx,ou=xxx,ou=xxxx,o=xx,c=uk",
"is_staff": "cn=somegroup,ou=xxx,ou=xxx,ou=xxx,ou=xxxx,o=xx,c=uk",
"is_superuser": "cn=somegroup,ou=xxx,ou=xxx,ou=xxx,ou=xxxx,o=xx,c=uk"
}
** Omitted for clarity**
# ldapsearch -x -H ldap://ldap.xxxxxxxxxxx.xx.uk/ cn=somegroup
# extended LDIF
#
# LDAPv3
# base <> (default) with scope subtree
# filter: cn=somegroup
# requesting: ALL
#
# somegroup, xx, xxx, xxxx, xx, uk
dn: cn=somegroup,ou=xx,ou=xxx,ou=xxxx,o=xx,c=uk
objectClass: groupOfNames
objectClass: top
member;x-static:cn=someusername,ou=xxxx,ou=xxx,ou=xxx,o=xx,c=uk
cn:somegroup
# ldapsearch -x -H ldap://ldap.xxxxxxxxxxx.xx.uk/ cn=someusername
someusername, xxxx, xxx, xxx, xx, uk
dn: cn=someusername,ou=xxxx,ou=xxx,ou=xxx,o=xx,c=uk
uniqueID: someusername
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: ndsLoginProperties
objectClass: person
objectClass: top
objectClass: posixAccount
objectClass: posixGroup
groupMembership: cn=somegroup,ou=xx,ou=xxx,ou=xxxx,o=xx,c=uk
cn: someusername