Wednesday, April 18, 2018

Search Ldap Server Special User Attributes:


In LDAP Server ,if you create a user ,the user has many built  in attributes like dn,and cn.this properties can be retrieved from the Ldap server using any of the Java available Ldap Client Search Query . But several special attributes like group attributes ,ex:memberof can not be retreived from Ldap server using any Search queries. Because by default the special attributes are not available to the Clients search filter ,  so to retrieve the Special attributes via Ldap Client add the below lines in your Ldap Client Search Query.Here i am using Java available LDAP Supporting Client.


The classes used are imported from javax API.
//import javax.naming.directory.SearchControls;
//import javax.naming.directory.SearchResult;


Frame your Search Control as mentioned here:

                SearchControls searchControls = new SearchControls();
                searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                searchControls.setReturningAttributes(new String[] { "*", "+" });

 This will retreive all attributes including Special attributes like memberof and many attributes.

 Code to Search for All attributes from Ldap Server:
                     NamingEnumeration<SearchResult> resultData = context.getSystemLdapContext().search(getUserDn(userName), filterExpresssion, searchControls);
                     SearchResult result = resultData.next();
                     Attribute att = result.getAttributes().get("memberOf");


Any doubts add in comment.

LDAP Configuration with Shiro:

What is LDAP? LDAP is Lightweight Directory Access Protocol. LDAP is a global directory service, industry-standard protocol, which is...