Posted By

nialace on 04/29/11


Tagged

ldap unboundid


Versions (?)

in memory ldap directory with unboundid


 / Published in: Java
 

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. import com.unboundid.ldap.listener.InMemoryDirectoryServer;
  6. import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
  7. import com.unboundid.ldap.sdk.LDAPConnection;
  8. import com.unboundid.ldap.sdk.LDAPException;
  9. import com.unboundid.ldap.sdk.SearchResultEntry;
  10.  
  11.  
  12. public class main5 {
  13.  
  14. /**
  15.   * @param args
  16.   * @throws LDAPException
  17.   */
  18. public static void main(String[] args) throws LDAPException {
  19.  
  20. // Create the configuration to use for the server.
  21. InMemoryDirectoryServerConfig config =
  22. new InMemoryDirectoryServerConfig("dc=ilex-si,dc=eu");
  23. config.addAdditionalBindCredentials("cn=Directory Manager", "password");
  24.  
  25. // Create the directory server instance, populate it with data from the
  26. // "test-data.ldif" file, and start listening for client connections.
  27. InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
  28. ds.importFromLDIF(true, "data.ldif");
  29. ds.startListening();
  30.  
  31. System.out.println("port="+ds.getListenPort());
  32.  
  33.  
  34. // Get a client connection to the server and use it to perform various
  35. // operations.
  36. LDAPConnection conn = ds.getConnection();
  37. SearchResultEntry entry = conn.getEntry("dc=ilex-si,dc=eu");
  38.  
  39. // Do more stuff here....
  40. String response = null;
  41. System.out.println("write something : ");
  42.  
  43. try {
  44. response = br.readLine();
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48.  
  49. System.out.println("you entered :"+response);
  50.  
  51. // Disconnect from the server and cause the server to shut down.
  52. conn.close();
  53. ds.shutDown(true);
  54.  
  55. }
  56.  
  57. }

Report this snippet  

You need to login to post a comment.