【问题标题】:Get list of Active Directory users with authenticated identity thru Waffle (Java)?通过 Waffle (Java) 获取具有经过身份验证的身份的 Active Directory 用户列表?
【发布时间】:2015-09-01 13:47:10
【问题描述】:

我想让用户无需输入密码即可验证并检索完整的 Active Directory 用户列表。我可以通过 Waffle 轻松进行身份验证,并且可以查询特定于经过身份验证的用户的信息,例如他们所属的组列表。但是,Waffle 似乎无法进行更一般的查询,例如完整的用户列表(甚至是属于某个组的用户列表)。

我配置了另一个玩具示例,我使用 JNDI 查询用户列表,效果很好,但它需要用户名和密码才能建立连接。

假设我的 AD 服务器上禁用了匿名查询,我有什么方法可以使用我通过 Waffle 建立的经过身份验证的会话来查询用户列表?

【问题讨论】:

    标签: java active-directory ldap waffle


    【解决方案1】:

    想通了,以防万一有人感兴趣。老实说,我没有得到答案,也没有在网上的某个地方找到明确的解决方案,这让我感到惊讶。事实证明,对于简单的用户列表查询,Waffle 是不必要的 - 我修改了 the code sample here 以生成以下方法来解决问题:

    static void queryCom4j(){ 
      IADs rootDSE = COM4J.getObject(IADs.class, "LDAP://RootDSE", null);
      String namingContext = (String)rootDSE.get("defaultNamingContext");
    
      _Connection conn = ClassFactory.createConnection();
      conn.provider("ADsDSOObject");
      conn.open("Active Directory Provider","","",-1);
    
      _Command cmd = ClassFactory.createCommand();
      cmd.activeConnection(conn);
    
      String fields = "distinguishedName,userPrincipalName,telephoneNumber,mail";
      String query = "(&(objectclass=user)(objectcategory=person))";
    
      cmd.commandText("<LDAP://" + namingContext + ">;" + query + ";" + fields + ";subTree");
      _Recordset rs = cmd.execute(null, Variant.getMissing(), -1);
    
      System.out.println("Found " + rs.recordCount() + " users");
      while (!rs.eof()){
          for (int i = 0; i < fields.split(",").length; i++){
              Object value = rs.fields().item(i).value();
              System.out.println((value == null) ? "N/A" : value.toString());
          }
          rs.moveNext();
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2012-05-25
      • 2011-10-30
      • 1970-01-01
      • 2019-10-04
      • 2011-02-12
      相关资源
      最近更新 更多