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
Alles anzeigen
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
- import java.util.Hashtable;
- import javax.naming.*;
- import javax.naming.directory.*;
- public class LDAP_reader {
- public static void main(String[] args) {
- new LDAP_reader();
- }
- public LDAP_reader(){
- Hashtable hstEnvironment = new Hashtable();
- hstEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- hstEnvironment.put(Context.PROVIDER_URL, "ldap://ldap00.mydomain.eu:389/ou=AbteilungXY");
- try {
- DirContext oContext = new InitialDirContext(hstEnvironment);
- Attributes oAnswer = oContext.getAttributes("Node=NodeNameZ,ou=CONFIG");
- // Loop ueber die Attribute
- System.out.println("Attribute:");
- System.out.println(" Wert:");
- System.out.println("********************");
- for (NamingEnumeration ae = oAnswer.getAll(); ae.hasMore();) {
- // Attribute ermitteln
- Attribute oAttr = (Attribute) ae.next();
- System.out.println(oAttr.getID());// Attribute
- // Attributwerte ausgeben
- for (NamingEnumeration e = oAttr.getAll();
- e.hasMore();
- System.out.println(" " + e.next())); // Wert
- }
- }
- catch (NamingException ne) {
- System.out.println("Leseoperation fehlgeschlagen!");
- ne.printStackTrace();
- }
- }
- }