2011-06-13 8 views
0

현재 내 코드가 있습니다. 사용자/컴퓨터가 적용한 정책을 결정하기 위해 Active Directory를 검색하는 Java 프로그램을 만들고 있습니다. 이것은 현재 진행중입니다. 다음은 사용자에게 정책을 추가하는 기능을 추가하겠습니다. 그러나 아래의 정책을 확인할 때 사용자가 존재하지 않거나 사용자에게 정책이없는 경우 결과가 산출되지 않습니다. 알아낼 수없는 것은 사용자가 존재하지 않는지 확인하는 것입니다. 어떤 도움을 주시면 감사하겠습니다.검색을위한 자바 프로그램

public class memberOf { 

    ArrayList results; 

    memberOf(String computerName){ 

     Hashtable env = new Hashtable(); 
     //String adminName = "CN=Administrator,CN=Users,DC=ANTIPODES,DC=COM"; 
     //String adminPassword = "XXXXXXX"; 
     String ldapURL = "n"; 
     env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); 
     //set security credentials, note using simple cleartext authentication 
     env.put(Context.SECURITY_AUTHENTICATION,"simple"); 


     env.put(Context.SECURITY_PRINCIPAL,"u"); 
     System.out.println("Enter password"); 
     Scanner in = new Scanner(System.in); 
     String password = in.nextLine(); 



     env.put(Context.SECURITY_CREDENTIALS,password); 
     //env.put(Context.SECURITY_PROTOCOL, "ssl"); 



     //connect toSdomain controller 
     env.put(Context.PROVIDER_URL,ldapURL); 

     try { 

      //Create the initial directory context 
      LdapContext ctx = new InitialLdapContext(env,null); 


      //Create the search controls   
      SearchControls searchCtls = new SearchControls(); 

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

      //specify the LDAP search filter 
      String searchFilter= "CN="+computerName; 

      //Specify the Base for the search 
      String searchBase = "DC=n,DC=o"; 

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


      //Specify the attributes to return 
      String returnedAtts[]={"memberOf"}; 
      searchCtls.setReturningAttributes(returnedAtts); 

      //Search for objects using the filter 
      NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls); 


      results = new ArrayList(); 
       while (answer.hasMoreElements()) { 

        SearchResult sr = (SearchResult)answer.next(); 

        Attributes attrs = sr.getAttributes(); 


        try { 

         for (NamingEnumeration ae = attrs.getAll();ae.hasMore();) { 
          Attribute attr = (Attribute)ae.next();       

          for (NamingEnumeration e = attr.getAll();e.hasMore();totalResults++) { 

           String tempStr = (String)(e.next()); 
           int start = tempStr.indexOf("_"); 
           int end = tempStr.indexOf(","); 
           tempStr=tempStr.substring(start, end);       
           results.add(totalResults,tempStr);        

          } 

         } 

        }  
        catch(Exception e){ 
         e.printStackTrace(); 
        }     

       } 
     ctx.close();   
     }  
     catch (NamingException e) { 
      e.printStackTrace(); 
     } 

    } 
    public ArrayList getResults(){ 
     System.out.println(results.size()); 
     if(results.size()==0){ 
      results.add(0, "No Groups"); 
     } 
     return(results); 
    } 

} 

답변

2

그런 식으로 찾을 수 없습니다. 사용자 (upn, samAccountName 등)에서 검색 할 속성을 알고 그런 식으로 찾은 다음 사용자 객체의 backlinked 속성을 사용하여 정책을 찾으십시오.

역으로 정책을보고 "이 정책의 구성원은 누구입니까?"라고 묻는 것처럼 보입니다. 사용자가 존재하지만

  • 사용자가 전혀 존재하지 않는 구성원이 아닌
    • 구별 할 수없는 분명하지만 - 그것은 잘 작동합니다.