This piece of code will work with unknown attribute names and one or more values โโ(for example, several classes of objects):
Using spring -ldap 2.3.1 and the Mapper Attributes :
<dependency> <groupId>org.springframework.ldap</groupId> <artifactId>spring-ldap-core</artifactId> <version>2.3.1.RELEASE</version> </dependency>
In this code example, searchResultList contains all the records, each of which is represented as an attribute map (with one or more values):
List<Map<String, List<String>>> searchResultList = sourceLdapTemplate.search(searchBase, filter.encode(), SearchControls.ONELEVEL_SCOPE, new AttributesMapper<Map<String, List<String>>>() { @Override public Map<String, List<String>> mapFromAttributes(Attributes attributes) throws NamingException { Map<String, List<String>> attrsMap = new HashMap<>(); NamingEnumeration<String> attrIdEnum = attributes.getIDs(); while (attrIdEnum.hasMoreElements()) {
Now working with searchResultList looks like this:
for (Map<String, List<String>> attrsMap : searchResultList) { for (String objectClass : m.get("objectClass")) {
source share