on 04-06-2006 11:46 AM
I am having problem in running the below code, can someone pls help me out with it ? It either doesn't return anything or gives error code 32.
import javax.naming.*;
import javax.naming.ldap.*;
import java.util.*;
import javax.naming.directory.*;
public class ldapdemo {
public static void main(String[] args) {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "LDAP://dewdfx1b1:389");
LdapContext ldapctx = new InitialLdapContext(env, null);
Attributes matchAttrs = new BasicAttributes();
matchAttrs.put("uid","I028949");
String [] attrIDs = {"cn","mail"};
NamingEnumeration answer = ldapctx.search("o=SAP", matchAttrs, attrIDs);
while(answer.hasMore()) {
SearchResult sr = (SearchResult)answer.next();
Attributes resultAttrs = sr.getAttributes();
String username = resultAttrs.get("cn").getID();
String mail = resultAttrs.get("mail").getID();
System.out.println("username="+username);
System.out.println("mail="+mail);
}
} catch (NamingException e) {
System.out.println(e.getMessage());
return;
}
}
}
Sameer,
First, I see no authentication in your coding. Probably it is required.
Second, where is base DN for binding?
Try this sample (for InitialContext info with credentials):
http://www.sgi.nu/diary/2005/10/27/accessing-the-global-address-list-in-ms-exchange-from-java/
Also I highly recommend to download Java LDAP browser/editor and try to perform your program task it:
http://www-unix.mcs.anl.gov/~gawor/ldap/
Valery Silaev
EPAM Systems
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.