Java implementation of Apache DS management
Ldapconnection connection = new Ldapnetworkconnection ("localhost", 10389);
Detect connection Status @Test public void Testsimplebindrequest () throws ldapexception { connection.bind ("Uid=admin,ou=system", "secret"); connection.unbind (); assert.assertfalse (connection.isconnected ()); Assert.assertfalse (connection.isauthenticated ()); } //Simple Query @Test public void Testsimplesearch () throws Ldapexception, cursorexception,ioexception { connection.bind ("uid=admin,ou= System "," secret "); entrycursor cursor = Connection.search (" ou= System "," (objectclass=*) ", searchscope.onelevel); while ( Cursor.next ()) {    &NBSp; entry Entry = Cursor.get (); assert.assertnotnull (Entry);      SYSTEM.OUT.PRINTLN (entry); } cursor.close (); connection.close (); } //Query with Constraints @ test public void Testcomplexsearches () throws Ldapexception, Cursorexception,ioexception { connection.bind ("Uid=admin,ou=system", "secret"); searchrequest req = new Searchrequestimpl (); req.setscope (Searchscope.subtree); Req.addattributes ("*"); req.settimelimit (0); Req.setbase (New Dn ("Ou=system")); req.setfilter ("(ou=consumers)" ); searchcursor searchcursor = Connection.search (req); while (Searchcursor.next ()) { response Response = Searchcursor.get (); if (response instanceof SearchResultEntry) { entry resultentry = ((SearchResultEntry) Response). Getentry (); assert.assertnotnull (resultentry); &Nbsp; system.out.println (resultentry); } } Searchcursor.close (); connection.close (); } //Add entry @Test public void Testaddldif () throws Ldapexception, IOException { connection.bind (" Uid=admin,ou=system "," secret "); connection.add (New DefaultEntry ( "Cn=testadd,ou=system", "Objectclass:top", "Objectclass:person", "CN:TESTADD_CN", "SN:TESTADD_SN")); connection.close (); } //add entry in the requested way @Test public void Testaddwithcontrol () throws Ldapexception, Ioexception { connection.bind ("Uid=admin,ou=system", "secret"); entry Entry = new Defaultentry ("Cn=testadd2,ou=system", " Objectclass:top "," Objectclass:person "," SN:TESTADD_SN "); Addrequest addrequest = new Addrequestimpl (); addrequest.setentry ( Entry); addrequest.addcontrol (new Managedsaitimpl ()); addresponse response = Connection.add (addrequest); assert.assertnotnull (response); Assert.assertequals (Resultcodeenum.success, Response.getldapresult (). Getresultcode ()); connection.close (); } //Delete entry @Test public void Testdeleteleafnode () throws Ldapexception, IOException { connection.bind ("Uid=admin,ou=system", "secret"); connection.delete ("Cn=testadd,ou=system"); Connection.close (); } //Delete entry @Test public void Testmodify () throws Ldapexception, IOException { connection.bind ("Uid=admin,ou=system", "secret"); Modification Addedgivenname = new Defaultmodification (Modificationoperation.add_attribute, "GivenName"); connection.modify ("uid=doe,dc=acme,dc=com", AddedGivenName); connection.close (); }
Apacheds Client