Reputation: 75
I want to retrieve all users from LDAP AD directory and store it in a file for some processing. I am using below code to fetch all AD users but it's returning No Attributes.
try {
DirContext ctx = new InitialDirContext(env);
connected = "true";
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = { "(&(objectClass=*)(objectCategory=*))"};
constraints.setReturningAttributes(attrIDs);
NamingEnumeration<SearchResult> answer = ctx.search(ldapDCinfo, "(&(objectClass=*)(objectCategory=*))", constraints);
while (answer.hasMore()) {
Attributes attrs = ((SearchResult) answer.next()).getAttributes();
sendAry[0]= connected;
System.out.println(attrs.toString());
}
Upvotes: 0
Views: 140
Reputation: 311023
String[] attrIDs = { "(&(objectClass=*)(objectCategory=*))"};
constraints.setReturningAttributes(attrIDs);
This is nonsense. That's not an array of attribute IDs, it is an array containing one filter string, and the filter string is already specified elsewhere.
If for example you want to return surname, givenName, mail
, you would write:
String[] attrIDs = { "surname", "givenName", "mail"};
If you want all the normal attributes, use "*"
. If you want the operational attributes as well, use:
String[] attrIDs = { "*", "+"};
Upvotes: 1