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);
}
}