I am trying to return employee numbers of everyone in search filter (&(employeeType= Workforce)(objectClass=person))This is my code:import java.util.Enumeration;import java.util.Properties;import javax.naming.Context;import javax.naming.NamingEnumeration;import javax.naming.NamingException;import javax.naming.directory.Attributes;import javax.naming.directory.Attribute;import javax.naming.directory.DirContext;import javax.naming.directory.InitialDirContext;import javax.naming.directory.SearchControls;import javax.naming.directory.SearchResult;import java.util.Hashtable;import javax.naming.ldap.InitialLdapContext;import javax.naming.ldap.LdapContext;public class testing2 {    public testing2() {    }    public void doLookup() {        Properties properties = new Properties();        properties.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.ldap.LdapCtxFactory);        properties.put(Context.PROVIDER_URL, removed for reasons);        properties.put(Context.SECURITY_AUTHENTICATION,simple);        properties.put(Context.SECURITY_PRINCIPAL,removed);         properties.put(Context.SECURITY_CREDENTIALS,secret);        try {            DirContext context = new InitialDirContext(properties);            SearchControls searchCtrls = new SearchControls();            searchCtrls.setSearchScope(SearchControls.SUBTREE_SCOPE);            String filter = (&(employeeType= Workforce)(objectClass=person));            NamingEnumeration values = context.search(o = xyz,filter,searchCtrls);            while (values.hasMoreElements())            {                SearchResult result = (SearchResult) values.next();                Attributes attribs = result.getAttributes();                if (null != attribs)                {                    for (NamingEnumeration ae = attribs.getAll(); ae.hasMoreElements();)                    {                        Attribute atr = (Attribute) ae.next();                        String attributeID = atr.getID();                        for (Enumeration vals = atr.getAll();                             vals.hasMoreElements();                             System.out.println(attributeID +: + vals.nextElement()));                            //System.out.println(attributeID.getAttributes().get(uid))                    }                }            }            context.close();        } catch (NamingException e) {            e.printStackTrace();        }    }    public static void main(String[] args) {        testing2 sample = new testing2();        sample.doLookup();    }}The thing is that when I run this, I get everything/all information about all the users - including attributes like first name, last name, title, givenName, postal code, employee number and more. How do I go about JUST extracting/returning the employee numbers only (for all users within the filter). Additionally, what can be done to clean up/make the code better?With some aid, I came to this:SearchResult result = (SearchResult) values.next();                Attributes attribs = result.getAttributes();                Attribute myattrib = attribs.get(employeeNumber);                if (null != attribs)                {                    for (NamingEnumeration ae = attribs.getAll(); ae.hasMoreElements();)                    {                        Attribute atr = (Attribute) ae.next();                        String attributeID = atr.getID();                        for (Enumeration vals = atr.getAll();                            vals.hasMoreElements();                             System.out.println(attributeID +: + vals.nextElement()));                         I am unsure of where Attribute myattrib = attribs.get(employeeNumber); goesthanks a lot!
How to return specific attributes for all users in LDAP Java?
java;ldap