jQuery in Action, 3rd edition
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 REST with Spring (video course) this week in the Spring 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://ldap.utexas.edu/o=The 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)answer.next();
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)ae.next();
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: " + e.next());
this.displayJTextArea.setText(displayJTextArea.getText() + "\n" + "value: " + e.next());
} 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
I agree. Here's the link: http://aspose.com/file-tools
subject: LDAP
It's not a secret anymore!