Merhaba, aşağıda gönderdiğim kod ile active directory e bağlanıp bütün kullanıcıların isimlerini soysimilerini ve email adreslerini çekmek istiyorum. İlk once garip bir hata alıyordum
appserv-tr.jar dosyasını lib e ekledim. Bir forum sitesinde onu ekledim oldu diye bir yazı okumustum. Ama bu sefer de yine aşağıdaki hatayı aldım. Bunun nasıl üstesinden geleceğim bilmiyorum. Yardımcı olabilir misiniz ?
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
import javax.naming.ldap.InitialLdapContext;
import javax.swing.text.AbstractDocument.Content;
/**
*
* @author CanCobanoglu
*/
public class ActiveDirectory {
public static void main(String args[]) {
Hashtable env = new Hashtable();
String adminName = "CN=sifre,CN=Users,DC=SCHOTT,DC=ORG";
String adminPassword = "*********";
String ldapURL = "ldap://ip";
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
env.put(Context.PROVIDER_URL,ldapURL);
try {
DirContext ctx = new InitialLdapContext(env, null);
SearchControls searchCtls = new SearchControls();
String returnedAtts[]={"sn","givenName","mail"};
searchCtls.setReturningAttributes(returnedAtts);
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String searchFilter = "(&(objectClass=user)(mail=*))";
String searchBase = "DC=SCHOTT,DC=ORG";
int totalResults = 0;
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
totalResults++;
System.out.println(">>>" + sr.getName());
// Print out some of the attributes, catch the exception if the attributes have no values
Attributes attrs = sr.getAttributes();
if (attrs != null) {
try {
System.out.println(" surname: " + attrs.get("sn").get());
System.out.println(" firstname: " + attrs.get("givenName").get());
System.out.println(" mail: " + attrs.get("mail").get());
}
catch (NullPointerException e) {
System.out.println("Errors listing attributes: " + e);
}
}
}
System.out.println("Total results: " + totalResults);
ctx.close();
} catch (NamingException ex) {
System.err.println("Problem searching directory: " + ex);
}
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/logging/LogDomains
at com.sun.enterprise.util.ORBManager.<clinit>(ORBManager.java:78)
at com.sun.enterprise.naming.SerialInitContextFactory.<clinit>(SerialInitContextFactory.java:56)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:134)
at External.ActiveDirectory.main(ActiveDirectory.java:35)
Caused by: java.lang.ClassNotFoundException: com.sun.logging.LogDomains
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 10 more
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
www.cancobanoglu.net
www.bilisimdergi.com
cancobanoglu@gmail.com
|