Posted By

nialace on 04/29/11


Tagged

java unboundid


Versions (?)

ldap search using sample object


 / Published in: Java
 

  1. import com.unboundid.ldap.sdk.LDAPConnection;
  2. import com.unboundid.ldap.sdk.LDAPException;
  3. import com.unboundid.ldap.sdk.persist.LDAPPersister;
  4. import com.unboundid.ldap.sdk.persist.PersistedObjects;
  5.  
  6.  
  7. public class main4 {
  8.  
  9. /**
  10.   * @param args
  11.   * @throws LDAPException
  12.   */
  13. public static void main(String[] args) throws LDAPException {
  14.  
  15.  
  16. LDAPConnection connection = new LDAPConnection("localhost", 389, "cn=Directory Manager", "secret");
  17.  
  18. InetOrgPerson person = new InetOrgPerson();
  19. person.setSn("test");
  20. person.setCn("test");
  21. person.setUid("test");
  22.  
  23.  
  24. // Create an LDAPPersister instance for MyObject objects.
  25. LDAPPersister<InetOrgPerson> persister = LDAPPersister.getInstance(InetOrgPerson.class);
  26.  
  27. //persister.add(person, connection, null);
  28.  
  29.  
  30. // Perform a search to find all instances with a string value of "test",
  31. // then delete them from the server.
  32. InetOrgPerson o = new InetOrgPerson();
  33. o.setUid("test");
  34. PersistedObjects<InetOrgPerson> results = persister.search(o, connection);
  35. while (true)
  36. {
  37. o = results.next();
  38. if (o == null)
  39. {
  40. break;
  41. }
  42.  
  43.  
  44. System.out.println(o);
  45.  
  46. }
  47.  
  48.  
  49. }
  50.  
  51. }

Report this snippet  

You need to login to post a comment.