java - Ldap searchFilter 字符串不等于 memberOf OU ="Google app user"和 OU ="Contacts"

标签 java active-directory ldap jndi

我必须获取不属于组 OU="Google app User"和 OU=Contacts 的用户的数据,我不知道创建搜索过滤字符串。代码如下---

public SearchResult getUserInfo(DirContext ctx) throws NamingException{
    SearchResult sourceResult = null;
     // Create the search controls          
    SearchControls searchCtls = new SearchControls(); 

      //Specify the attributes to return 
   //1   String returnedAtts[]={"ou","description"}; // array of the object list  which is returned as the 
                                    //result of the search query on ldap active directory

     String returnedAtts[]={"cn","description","memberOf"};
    searchCtls.setReturningAttributes(returnedAtts); 
      logger.info("Specify the attributes to return ");

      //Specify the search scope 
      searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); 
      logger.info("Specify the search scope  ");

      //specify the LDAP search filter 
  //1    String searchFilter = "(&(OU=Contacts))"; // search input  variable   require to search the  result   active directory 
      String searchFilter = "(&(OU=Contacts))";// I wanna  create search          filter for all reseult which are not group member of OU="google app user"
  and OU="contacts".          
      logger.info("specify the LDAP search filter  ");

      //Specify the Base for the search 
     //1 String searchBase ="DC=Hellowveen,DC=com";
      String searchBase ="OU=Users,OU=Matriz,OU=Brazil,DC=Hellowveen,DC=com";// "dc=dom,dc=fr";  initial basic search directory
      logger.info("Specify the Base for the search  ");

      //initialize counter to total the results 
      int totalResults = 0; 

      // Search for objects using the filter 
      NamingEnumeration<SearchResult> answer = ctx.search(searchBase, searchFilter, searchCtls); 
      logger.info("Search for objects using the filter  ");

      //Loop through the search results 
      while (answer.hasMoreElements()) 
      { 
        sourceResult = (SearchResult)answer.next(); 

        totalResults++; 

        System.out.println(" get name : >>>" + sourceResult.getName()); 
        System.out.println(" get class name :>>>" +      sourceResult.getClassName()); 
        Attributes attrs = sourceResult.getAttributes(); 
        System.out.println("member Off>>>>" + attrs.get("memberOf")); 

      } 
      logger.info("Loop  END through the search results  ");
      System.out.println("Total results: " + totalResults); 
      ctx.close(); 


    return sourceResult; 
}

如何使用基于 group(memberOf) 的 java 来搜索 Activity 目录中的数据。我真的很感激每一个建议解决方案。谢谢

最佳答案

LDAP 文件管理器搜索字符串表示形式:RFC 2254

过滤所有不属于“Google 应用用户” 组成员但属于联系人组成员的用户:

(&(!(memberOf=ou=Google app User))(memberOf=ou=Contacts))

关于java - Ldap searchFilter 字符串不等于 memberOf OU ="Google app user"和 OU ="Contacts",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32246316/

相关文章:

javac找不到已经安装在jre/lib/ext中的jar文件

.net - 我如何使用 .net 3.5 或 4 中的 DirectoryServices.AccountManagement 在 Active Directory 中创建新的 OU

active-directory - 如何在 CMD 中查找没有用户名的用户全名?

c# 通过 LDAP 针对 Active Directory

java - 如何使用 FEST 断言列表不包含某些内容?

java - 显示一个数字的另一个数字的幂 - 上标

asp.net - .NET 3.5 DirectoryServices.AccountManagement 中的等效名称解析 (anr=*ma*)

ldap - Openldap:是否可以使用 "userPassword"而不是 "2.5.4.35"作为 pwdAttribute?

java - 如何使用java为MySQL启用LDAP连接?

java - 用Java将两个列表合并为一个“二维”列表