Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LDAP

 
Alan Jackson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
//printAttrs(sr.getAttributes());

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) {
e.printStackTrace();
}
}


}
 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store all the elements in HashMap as a key value pair, and then retrieve it 1 by 1.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"anumishra1",
Please see the thread here to prevent your account being deleted.

David O'Meara
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic