【问题标题】:Using the django-auth-ldap LDAPSearch to search two OUs使用 django-auth-ldap LDAPSearch 搜索两个 OU
【发布时间】:2018-08-21 17:31:19
【问题描述】:

我有一个容器化应用程序,它使用 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)")

【问题讨论】:

    标签: django django-auth-ldap


    【解决方案1】:

    取自updated documentation

    1.1 版中的新功能。

    如果您需要在多个地方搜索用户,您可以使用 LDAP 搜索联合。这需要多个 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)"),
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 2013-09-16
      • 2012-02-29
      相关资源
      最近更新 更多