I am using below code to retrieve all users from TDS LDAP using Java API. But when I include image in return attributes, the query doesn't work. Please help me fix it.
String returnedAtts[] = {"jpegPhoto","cn","uid","UserAccountStatus"};
When i include attribute "jpegPhoto", i am getting empty results.
but without attribute "jpegPhoto" like below, am getting all users data.i need images of all users also so query (cn=*) not working with image attribute.
String returnedAtts[] = {"uid","cn","UserAccountStatus"};
try {
// Create the initial directory context
DirContext ctx = new InitialLdapContext(env,null);
//Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the attributes to return
String returnedAtts[]={"jpegPhoto","DateofBirth","DateofJoining","cn","sn","UserAccountStatus","uid"};
//String returnedAtts[]={"DateofBirth","DateofJoining","cn","sn","UserAccountStatus","uid"};
searchCtls.setReturningAttributes(returnedAtts);
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String searchBase = "cn=parleRealm,o=parle";
int totalResults = 0;
// Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, "(&(objectClass=inetOrgPerson)(cn=*))", searchCtls);
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
totalResults++;
// Print out some of the attributes, catch the exception if the attributes have no values
Attributes attrs = (Attributes) sr.getAttributes();
if (attrs != null) {
try {
if("Active".equals(attrs.get("UserAccountStatus").get().toString())){
/*
ub=new UserBean();
ub.setUid((String)attrs.get("uid").get());
ub.setCn((String)attrs.get("cn").get());
ub.setSn((String)attrs.get("sn").get());
ub.setDateOfBirth((String)attrs.get("DateofBirth").get());
ub.setDateofJoining((String)attrs.get("DateofJoining").get());
list.add(ub);*/
System.out.println(attrs.get("cn").get());
}
}
catch (Exception e) {
System.out.println(attrs.get("uid").get()+"is failed to read");
}
}
}
I am getting below error while fetching all users data from TDS ldap using java api.
My code is
but i am getting all users data if i remove "jpegPhoto" return attributes.