Apacheds's Client

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.