Zugriff via JNDI auf LDAP

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Zugriff via JNDI auf LDAP

    Hallo zusammen

    ich sollte einige statistische informationen aus einem LDAP auslesen.
    mit dem unten abgebildeten code kann ich die Informationen zum Node "NodeNameZ" des Typ "CONFIG" auslesen. Ich würde jedoch ein Mechanismus (Query) benötigen, der mir alle Nodes des Typ "CONFIG" zurückgibt.

    hat jemand eine Idee wie man das macht?

    Danke für eure Antworten
    Gruss
    Stefan



    Quellcode

    1. import java.util.Hashtable;
    2. import javax.naming.*;
    3. import javax.naming.directory.*;
    4. public class LDAP_reader {
    5. public static void main(String[] args) {
    6. new LDAP_reader();
    7. }
    8. public LDAP_reader(){
    9. Hashtable hstEnvironment = new Hashtable();
    10. hstEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    11. hstEnvironment.put(Context.PROVIDER_URL, "ldap://ldap00.mydomain.eu:389/ou=AbteilungXY");
    12. try {
    13. DirContext oContext = new InitialDirContext(hstEnvironment);
    14. Attributes oAnswer = oContext.getAttributes("Node=NodeNameZ,ou=CONFIG");
    15. // Loop ueber die Attribute
    16. System.out.println("Attribute:");
    17. System.out.println(" Wert:");
    18. System.out.println("********************");
    19. for (NamingEnumeration ae = oAnswer.getAll(); ae.hasMore();) {
    20. // Attribute ermitteln
    21. Attribute oAttr = (Attribute) ae.next();
    22. System.out.println(oAttr.getID());// Attribute
    23. // Attributwerte ausgeben
    24. for (NamingEnumeration e = oAttr.getAll();
    25. e.hasMore();
    26. System.out.println(" " + e.next())); // Wert
    27. }
    28. }
    29. catch (NamingException ne) {
    30. System.out.println("Leseoperation fehlgeschlagen!");
    31. ne.printStackTrace();
    32. }
    33. }
    34. }
    Alles anzeigen