Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django auth ldap成员组不工作_Django_Ldap_Openldap_Ldap Query_Django Auth Ldap - Fatal编程技术网

django auth ldap成员组不工作

django auth ldap成员组不工作,django,ldap,openldap,ldap-query,django-auth-ldap,Django,Ldap,Openldap,Ldap Query,Django Auth Ldap,我设法使ldap身份验证工作正常,但用户组没有。对用户进行身份验证时,用户名、名字、电子邮件..等会复制到会话中,但布尔值(从用户所属的组中获取)不会复制到会话中 这是我的设置。py: AUTHENTICATION_BACKENDS = [ 'django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend', ] import ldap from django_auth_lda

我设法使ldap身份验证工作正常,但用户组没有。对用户进行身份验证时,用户名、名字、电子邮件..等会复制到会话中,但布尔值(从用户所属的组中获取)不会复制到会话中

这是我的设置。py:

AUTHENTICATION_BACKENDS = [
    'django_auth_ldap.backend.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
]


import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, GroupOfUniqueNamesType

AUTH_LDAP_SERVER_URI = "ldap://openldap"
AUTH_LDAP_BIND_DN = "cn=admin,dc=openldap"
AUTH_LDAP_BIND_PASSWORD = "admin"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=django,dc=openldap",
    ldap.SCOPE_SUBTREE, "(cn=%(user)s)")

AUTH_LDAP_USER_ATTR_MAP = {
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}

AUTH_LDAP_CACHE_TIMEOUT = 0
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 0
AUTH_LDAP_PROFILE_ATTR_MAP = {"home_directory": "homeDirectory"}
AUTH_LDAP_MIRROR_GROUPS = True
AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_ALWAYS_UPDATE_USER = True

AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=openldap",
    ldap.SCOPE_SUBTREE, "(objectClass=*)"
)
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn')

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
    'is_active': 'cn=active,ou=groups,dc=openldap',
    'is_staff': 'cn=staff,ou=groups,dc=openldap',
    'is_superuser': 'cn=superuser,ou=groups,dc=openldap',
}

# # Simple group restrictions
# AUTH_LDAP_REQUIRE_GROUP = 'cn=enabled,ou=groups,dc=openldap',
# AUTH_LDAP_DENY_GROUP = 'cn=disabled,ou=groups,dc=openldap',


### ERROR LOGGING

import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
这是我的ldap方案:

AUTHENTICATION_BACKENDS = [
    'django_auth_ldap.backend.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
]


import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType, GroupOfUniqueNamesType

AUTH_LDAP_SERVER_URI = "ldap://openldap"
AUTH_LDAP_BIND_DN = "cn=admin,dc=openldap"
AUTH_LDAP_BIND_PASSWORD = "admin"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=django,dc=openldap",
    ldap.SCOPE_SUBTREE, "(cn=%(user)s)")

AUTH_LDAP_USER_ATTR_MAP = {
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}

AUTH_LDAP_CACHE_TIMEOUT = 0
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 0
AUTH_LDAP_PROFILE_ATTR_MAP = {"home_directory": "homeDirectory"}
AUTH_LDAP_MIRROR_GROUPS = True
AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_ALWAYS_UPDATE_USER = True

AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=openldap",
    ldap.SCOPE_SUBTREE, "(objectClass=*)"
)
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn')

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
    'is_active': 'cn=active,ou=groups,dc=openldap',
    'is_staff': 'cn=staff,ou=groups,dc=openldap',
    'is_superuser': 'cn=superuser,ou=groups,dc=openldap',
}

# # Simple group restrictions
# AUTH_LDAP_REQUIRE_GROUP = 'cn=enabled,ou=groups,dc=openldap',
# AUTH_LDAP_DENY_GROUP = 'cn=disabled,ou=groups,dc=openldap',


### ERROR LOGGING

import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)

root用户是活动用户、职员和超级用户的一部分。
user1是active的一部分。
这是我从视图验证用户时得到的结果: 我得到错误->不是的成员

openldap        | 5b444c1f conn=1015 fd=13 ACCEPT from IP=172.23.0.4:47230 (IP=0.0.0.0:389)
openldap        | 5b444c1f conn=1015 op=0 BIND dn="cn=admin,dc=openldap" method=128
openldap        | 5b444c1f conn=1015 op=0 BIND dn="cn=admin,dc=openldap" mech=SIMPLE ssf=0
openldap        | 5b444c1f conn=1015 op=0 RESULT tag=97 err=0 text=
openldap        | 5b444c1f conn=1015 op=1 SRCH base="ou=django,dc=openldap" scope=2 deref=0 filter="(cn=root)"
openldap        | 5b444c1f <= mdb_equality_candidates: (cn) not indexed
openldap        | 5b444c1f conn=1015 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text=
django          | search_s('ou=django,dc=openldap', 2, '(cn=%(user)s)') returned 1 objects: cn=root,ou=django,dc=openldap
openldap        | 5b444c1f conn=1015 op=2 BIND anonymous mech=implicit ssf=0
openldap        | 5b444c1f conn=1015 op=2 BIND dn="cn=root,ou=django,dc=openldap" method=128
openldap        | 5b444c1f conn=1015 op=2 BIND dn="cn=root,ou=django,dc=openldap" mech=SIMPLE ssf=0
openldap        | 5b444c1f conn=1015 op=2 RESULT tag=97 err=0 text=
django          | Populating Django user root
openldap        | 5b444c1f conn=1015 op=3 BIND anonymous mech=implicit ssf=0
openldap        | 5b444c1f conn=1015 op=3 BIND dn="cn=admin,dc=openldap" method=128
openldap        | 5b444c1f conn=1015 op=3 BIND dn="cn=admin,dc=openldap" mech=SIMPLE ssf=0
openldap        | 5b444c1f conn=1015 op=3 RESULT tag=97 err=0 text=
openldap        | 5b444c1f conn=1015 op=4 CMP dn="cn=active,ou=groups,dc=openldap" attr="member"
openldap        | 5b444c1f conn=1015 op=4 RESULT tag=111 err=16 text=
django          | cn=root,ou=django,dc=openldap is not a member of cn=active,ou=groups,dc=openldap
openldap        | 5b444c1f conn=1015 op=5 CMP dn="cn=staff,ou=groups,dc=openldap" attr="member"
openldap        | 5b444c1f conn=1015 op=5 RESULT tag=111 err=16 text=
openldap        | 5b444c1f conn=1015 op=6 CMP dn="cn=superuser,ou=groups,dc=openldap" attr="member"
openldap        | 5b444c1f conn=1015 op=6 RESULT tag=111 err=16 text=
django          | cn=root,ou=django,dc=openldap is not a member of cn=staff,ou=groups,dc=openldap
django          | cn=root,ou=django,dc=openldap is not a member of cn=superuser,ou=groups,dc=openldap
openldap        | 5b444c1f conn=1015 op=7 SRCH base="dc=openldap" scope=2 deref=0 filter="(&(objectClass=*)(member=cn=root,ou=django,dc=openldap))"
openldap        | 5b444c1f <= mdb_equality_candidates: (member) not indexed
openldap        | 5b444c1f conn=1015 op=7 SEARCH RESULT tag=101 err=0 nentries=0 text=
django          | search_s('dc=openldap', 2, '(&(objectClass=*)(member=cn=root,ou=django,dc=openldap))') returned 0 objects:
openldap | 5b444c1f conn=1015 fd=13接受IP=172.23.0.4:47230(IP=0.0.0.0:389)
openldap | 5b444c1f conn=1015 op=0 BIND dn=“cn=admin,dc=openldap”方法=128
openldap | 5b444c1f conn=1015 op=0 BIND dn=“cn=admin,dc=openldap”mech=SIMPLE ssf=0
openldap | 5b444c1f conn=1015 op=0结果标签=97错误=0文本=
openldap | 5b444c1f conn=1015 op=1 SRCH base=“ou=django,dc=openldap”scope=2 deref=0 filter=“(cn=root)”

openldap | 5b444c1f我知道我要晚几年才能回答,但当我试图解决自己的问题时,在使用我的广告服务器时遇到了你的问题

从您的日志中,我可以看到如下消息:

django          | cn=root,ou=django,dc=openldap is not a member of cn=superuser,ou=groups,dc=openldap
对我来说,解决问题的是以下引用:

如果筛选器太具体,中间的组将是 忽略,导致组列表不完整

不要让你的过滤器太具体。反正也没什么大不了的, 由于只有用户属于这些组时才会返回这些组, 甚至间接地

虽然不适用于你的情况,可能与你的情况相反:我认为这是你问题的关键
django auth ldap
找不到您的组。我认为你是从根本上开始的,那就是DC。尝试将您的
AUTH\u LDAP\u GROUP\u SEARCH
更改为更具体一点,如以下所示,以查看这是否有帮助:

AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
    "OU=groups,DC=openldap",
    ldap.SCOPE_SUBTREE,
    "(objectClass=group)",
)

我无论如何都不是LDAP/AD方面的专家,所以YMMV。

有人吗?你有主意吗?