【问题标题】:How to make the LDAP filter to find value in three levels of OU如何使 LDAP 过滤器在 OU 的三个级别中查找值
【发布时间】:2017-07-21 05:31:16
【问题描述】:

对不起,我是 LDAP/AD 服务的新手,我在为服务器编写简单的 3 或 4 级 LDAP 查询时遇到问题,假设层次结构如下:

DN my.com.app (dc=my,dc=com,dc=app)
   |_OU maingroup
       |_OU subgroup
           |_OU grandsongroup

我尝试用当前登录用户(假设用户名是worker)获取grandsongroup中定义的所有值,所以这是我的过滤器

filter = "(&(ou=grandsongroup,ou=subgroup,ou=maingroup)(sAMAccountName=worker"))";

但它什么也没有返回,会出什么问题?

【问题讨论】:

    标签: java active-directory ldap


    【解决方案1】:
    1. 过滤器字符串没有定义搜索的深度。这是通过另一个参数完成的。有三种可能:

      • 仅当前级别
      • 当前级别加上一个子级别
      • 整个子树。
    2. 您要搜索的 DN 是在另一个参数中指定的,而不是在过滤器中。所以过滤字符串应该只是

      (sAMAccountName=worker)
      

      并且搜索的基本 DN 应该是

      ou=grandsongroup,ou=subgroup,ou=maingroup,dc=my,dc=com,dc=app
      

    【讨论】:

    • 谢谢。我还有一个问题:如何在上面的 DN 值中获取grandsongroup 下的值?是someResultSearch.getAttributes().get("ou").get()?
    • 如果ou是你想要的属性名,是的。
    • 非常感谢。但是如果像示例一样,在 3 级定义了三个 ou,但需要从 grandsongroup 中检索值怎么办?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多