Bestimmte LDAP Attribute in Einträgen ausgeben lassen

AlexD1979

Erfahrenes Mitglied
Hallo,
Ich bekomme es nicht hin, ein bestimmtes Attribut aus einem LDAP auszulesen. Ich habe alle Methoden über GetName oder getAttribut schon ausprobiert. Es will einfach nicht gelingen. Eine Ausgabe aller Attribute des Eintrages bekomme ich schon hin mit untenstehendem Quelltext. Aber wie bekomme ich Zugriff auf ein bestimmtes Attribut ?

...
public static void main (String args[])
{
try
{
//----------------------------------------------------------
// Bind an das LDAP herstellen
//----------------------------------------------------------

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);

env.put(Context.PROVIDER_URL, MY_HOST);

env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL, MGR_DN);
env.put(Context.SECURITY_CREDENTIALS, MGR_PW);

DirContext ctx = new InitialDirContext(env);


//----------------------------------------------------------
// Suchroutine
//----------------------------------------------------------

SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

NamingEnumeration results =
ctx.search(MY_SEARCHBASE, MY_FILTER, constraints);

while ( results != null && results.hasMore() )
{
SearchResult sr = (SearchResult) results.next();
String dn = sr.getName();
System.out.println ("Faurecia LDAP Server @ 190.86.1.45");
//System.out.println ("Der DN Name ist " +dn);
System.out.println ("Der DN Name ist :" +dn);

Attributes attrs = sr.getAttributes();


for (NamingEnumeration ne = attrs.getAll(); ne.hasMoreElements();)

{
Attribute attr = (Attribute)ne.next();
String attrID = attr.getID();

System.out.println (attrID+":");
for (Enumeration vals = attr.getAll();vals.hasMoreElements();)
{
System.out.println ("\t"+vals.nextElement());
}
}

System.out.println ("\n");
} // Ende der while-Schleife, die alle Ergebnisse der Abfrage zurückliefert.



} // Ende vom Try-Block

catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
 
Zurück