蟒蛇

寻找一些与django-auth-ldap软件包有关的帮助。

背景 - 我试图将LDAP用户添加到默认用户角色STAFF,ACTIVE和SUPERUSER。 您无疑可以从debug.log中看到,django-auth-ldap成功找到了LDAP用户名并相应地填充了DJANGO。

但是,它不会将LDAP用户添加到相关角色(活动,员工,超级用户),因为它表明它不属于相关组,但对用户名和组执行LDAP搜索时都会这样说。

任何帮助/建议将不胜感激。

谢谢

的debug.log

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

settings.py

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**

来自LDAP组搜索的输出###(省略了一些行)

# 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

来自LDAP用户名搜索的输出###(省略了一些行)

# 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
链接地址: http://www.djcxy.com/p/33699.html

上一篇: python

下一篇: How to use django