Not able to get DirContext ctx using Spring Ldap -


hi using spring ldap , after execution below program display here , after nothing happening, program in continue execution mode.

public class simpleldapclient {         public static void main(string[] args) {             hashtable env = new hashtable();             system.out.println("i here");             string principal = "uid="+"a502455"+", ou=people, o=ao, dc=com";             env.put(context.initial_context_factory,"com.sun.jndi.ldap.ldapctxfactory");             env.put(context.provider_url, "myurl");             env.put(context.security_authentication, "simple");             env.put(context.security_principal, principal);             env.put(context.security_credentials,"password");              dircontext ctx = null;             namingenumeration results = null;             try {                 ctx = new initialdircontext(env);                  system.out.println(" context" + ctx);                    searchcontrols controls = new searchcontrols();                 controls.setsearchscope(searchcontrols.subtree_scope);                 results = ctx.search("", "(objectclass=aoperson)", controls);                 while (results.hasmore()) {                     searchresult searchresult = (searchresult) results.next();                     attributes attributes = searchresult.getattributes();                     attribute attr = attributes.get("cn");                     string cn = (string) attr.get();                     system.out.println(" person common name = " + cn);                 }             } catch (namingexception e) {                 throw new runtimeexception(e);             } {                 if (results != null) {                     try {                         results.close();                     } catch (exception e) {                     }                 }                 if (ctx != null) {                     try {                         ctx.close();                     } catch (exception e) {                     }                 }             }         }       } 

try fixing below lines, removed "ao" , works fine.

results = ctx.search("", "(objectclass=person)", controls); 

you need give search base well

env.put(context.provider_url, "ldap://xx:389/dc=test,dc=enterprise,dc=xx,dc=com"); 

refer link http://www.adamretter.org.uk/blog/entries/ldaptest.java


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -