使用django-auth-ldap LDAPSearch搜索两个OU

Ben*_*enH 12 django django-auth-ldap

我有一个容器化的应用程序,它使用django-auth-ldap在Active Directory中搜索用户.我想结合两个独立OU的输出.是否有不同的方法或重载可能需要两个DN或一种方式来加入两个单独搜索的输出?

AUTH_LDAP_USER_SEARCH = LDAPSearch(os.environ.get('AUTH_LDAP_USER_SEARCH_BASEDN', ''),
                                ldap.SCOPE_SUBTREE,
                                "(sAMAccountName=%(user)s)")
Run Code Online (Sandbox Code Playgroud)

Jul*_*ian 6

取自更新的文档:

版本1.1中的新功能.

如果您需要在多个位置搜索用户,可以使用LDAPSearchUnion.这需要多个LDAPSearch对象并返回结果的并集.底层搜索的优先级未指定.

import ldap
from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion

AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(
    LDAPSearch("ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"),
    LDAPSearch("ou=otherusers,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)"),
)
Run Code Online (Sandbox Code Playgroud)