Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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
Python 3.x 从django-python3-ldap中的两个不同OU筛选帐户_Python 3.x_Django_Active Directory_Ldap - Fatal编程技术网

Python 3.x 从django-python3-ldap中的两个不同OU筛选帐户

Python 3.x 从django-python3-ldap中的两个不同OU筛选帐户,python-3.x,django,active-directory,ldap,Python 3.x,Django,Active Directory,Ldap,我们有一个django项目,用户可以使用本地广告访问登录。这很好,因为到目前为止我们只使用了一个OU。但是,我们现在需要从其他OU获取用户,这些OU与当前OU处于同一级别。我们怎样才能做到这一点 我们有以下设置: 设置.py # The LDAP search base for looking up users. LDAP_AUTH_SEARCH_BASE = 'DC=ypn,DC=local' # Custom setting LDAP_AUTH_FORMAT_SEARCH_FILTERS =

我们有一个django项目,用户可以使用本地广告访问登录。这很好,因为到目前为止我们只使用了一个OU。但是,我们现在需要从其他OU获取用户,这些OU与当前OU处于同一级别。我们怎样才能做到这一点

我们有以下设置:

设置.py

# The LDAP search base for looking up users.
LDAP_AUTH_SEARCH_BASE = 'DC=ypn,DC=local'
# Custom setting
LDAP_AUTH_FORMAT_SEARCH_FILTERS = 'project.ldap.custom_format_search_filters'
ldap.py:

from django_python3_ldap.utils import format_search_filters

def custom_format_search_filters(ldap_fields):
    # Call the base format callable.
    search_filters = format_search_filters(ldap_fields)
    # Advanced: apply custom LDAP filter logic.
    search_filters.append('(|(OU=office1)(OU=office2))')
    # All done!
    return search_filters
当我们运行python.\manage.py ldap\u sync\u用户时,它什么也没有给我们。我知道过滤是有效的,因为我可以按名称搜索,例如(sn=name),它会给我正确的结果


在没有任何过滤器的情况下运行搜索只会在大量“垃圾”帐户、已离开的用户、计算机等上产生结果,我们不想将所有这些垃圾都带上。

我不确定您是否已经了解到这一点,但看起来您正在尝试同步OU中的用户,而不是群中的用户。你离这件事太近了

例如,如果组名为office1和office2,则可以执行以下操作:

def custom_format_search_filters(ldap_fields):
    # Call the base format callable.
    search_filters = format_search_filters(ldap_fields)
    # Advanced: apply custom LDAP filter logic.
    search_filters.append('(|(CN=office1,OU=DistributionGroups,DC=domain,DC=com)(CN=office2,OU=SomeOtherOUOrEvenTheSameOU,DC=domain,DC=com))')
    # All done!
    return search_filters
我刚刚经历了与您相同的问题,发现我需要上下文名称,而不是组名称本身