This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes LDAP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "LDAP" Watch "LDAP" New topic


Alan Jackson

Joined: Oct 26, 2004
Posts: 26
Just a quick question about accessing an ldap server.

Im trying to list all the attributes from a server. The address of the one Ive been using is "ldap:// University of Texas at Austin,c=US"

My code access te server but only lists the first element (which is an ou). How do you either count the attributes in the server or keep going until all have been listed? My code is below. Id really appreciate a response.

while (answer.hasMoreElements()) {

SearchResult sr = (SearchResult);
System.out.println("\n>>>" + sr.getName());
this.displayJTextArea.setText(displayJTextArea.getText() + "\n" + sr.getName());

if (sr.getAttributes() == null) {
System.out.println("No attributes");
this.displayJTextArea.setText(displayJTextArea.getText() + "\n" + "No attributes");
} else {
try {
NamingEnumeration ae = sr.getAttributes().getAll();
while (ae.hasMore()) {
Attribute attr = (Attribute);
System.out.println("ATTRIBUTE: " + attr.getID());
this.displayJTextArea.setText(displayJTextArea.getText() + "\n" + "ATTRIBUTE: " + attr.getID());

NamingEnumeration e = attr.getAll();
while (e.hasMore()) {
System.out.println("value: " +;
this.displayJTextArea.setText(displayJTextArea.getText() + "\n" + "value: " +;
} catch (NamingException e) {

Anurag Mishra
Ranch Hand

Joined: Sep 27, 2001
Posts: 133
Store all the elements in HashMap as a key value pair, and then retrieve it 1 by 1.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Please see the thread here to prevent your account being deleted.

David O'Meara
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: LDAP
Similar Threads
[JNDI] Listing LDIF file via JNDI?
ldap hell
LDAP Connection
Getting password expiration from LDAP
AD LDAP Authentication & Data Fetch Error.