I am using spring-ldap-core-2.3.1.RELEASE.jar over JDK 1.8 and Tomcat 8.0 to access AD information via LdapTemplate . The title , department and company attributes are not returned by the ldapTemplate.search(..,.,..) method.
I use the following lines of code to search: -
LdapQuery ldapQuery = LdapQueryBuilder.query() .where("objectclass").is("user") .and("objectcategory").is("person") .and("cn").like(strWildcardText+"*"); ldapTemplate.search(ldapQuery, new ADUserAttributesMapper());
The following is the ADUserAttributesMapper class: -
public class ADUserAttributesMapper implements AttributesMapper<ADUserBean> { @Override public ADUserBean mapFromAttributes(Attributes attributes) throws NamingException { if(attributes==null) { return null; } adUserBean.setName((attributes.get("name")!=null) ? attributes.get("name").get().toString() : null); adUserBean.setCommonName((attributes.get("cn")!=null) ? attributes.get("cn").get().toString() : null); adUserBean.setDisplayName((attributes.get("displayname")!=null) ? attributes.get("displayname").get().toString() : null); adUserBean.setGivenName((attributes.get("givenname")!=null) ? attributes.get("givenname").get().toString() : null); // for FIRST NAME adUserBean.setMiddleName((attributes.get("initials")!=null) ? attributes.get("initials").get().toString() : null); // for MIDDLE NAME / INITIALS adUserBean.setLastName((attributes.get("sn")!=null) ? attributes.get("sn").get().toString() : null); // for LAST NAME adUserBean.setDepartment((attributes.get("department")!=null) ? attributes.get("department").get().toString() : null); adUserBean.setUserPrincipalName((attributes.get("userprincipalname")!=null) ? attributes.get("userprincipalname").get().toString() : null); // Logon Name adUserBean.setsAMAccountName((attributes.get("samaccountname")!=null) ? attributes.get("samaccountname").get().toString() : null); // Logon Name (pre-Windows 2000) adUserBean.setDistinguishedName((attributes.get("distinguishedname")!=null) ? attributes.get("distinguishedname").get().toString() : null); adUserBean.setMailID((attributes.get("mail")!=null) ? attributes.get("mail").get().toString() : null); adUserBean.setTitle((attributes.get("title")!=null) ? attributes.get("title").get().toString() : null); // Job Title adUserBean.setTelephoneNumber((attributes.get("telephonenumber")!=null) ? attributes.get("telephonenumber").get().toString() : null); adUserBean.setObjectCategory((attributes.get("objectcategory")!=null) ? attributes.get("objectcategory").get().toString() : null); return adUserBean; } }
The title , department and company attributes are for the Organization tab for the properties of the AD user, as shown in the figure below: 
In addition, on the General tab , the initials ( initials ) attribute is not initials / not specified Spring -LDAP LdapTemplate . The LdapQueryBuilder.query() object has access to the attributes(...) method, which takes a string array of attribute names to be retrieved. But even after mentioning them there, explicitly the values for attributes such as initials , title , department and company not returned.
The LDAP Browser plugin in the Eclipse IDE lists the title , department and company properties on the Organization tab without any problems.
Even the com4j API returns title , department and company attributes.
Is there any configuration that restricts the list of attributes or is it a restriction using the Spring-LDAP API? Are these attributes not part of BasicAttributes ? How to get these attributes using Spring-LDAP?
UPDATE (01-Aug-2017): A simple Java JNDI approach / code DOES NOT return the department , company , title attributes (even if these attributes are explicitly specified in the attribute array), but surprisingly it returns the initials attribute value.
UPDATE (02-Aug-2017): Similar to the @Pierre suggestion (below), I tried the following code using the SearchControls object: -
String strFilter= "(&(objectclass=top)(cn=cgma*))"; String[] attrs = new String[] {"cn","givenName","sn","initials","title","department","company"}; long maxResults = 10; // for example SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(attrs); searchControls.setCountLimit(maxResults); List<String> aLstOfADUsers = ldapTemplate.search("",strFilter,searchControls,new AttributesMapper<String>() { public String mapFromAttributes(Attributes attrs) throws NamingException { try { System.out.println(attrs.toString()); return attrs.get("cn").get().toString(); } catch(Exception ex) { ex.printStackTrace(); return null; } } }); return aLstOfADUsers;
Even this one does not return the value of the attributes initials , title , company and department .