title: Spring LdapTemplate - How do read values with same attribute name
body: <p>I would like to read all groups of a user and put them into a list.</p>
  
  <p>That's the ldap query:</p>
  
  <blockquote>
    <p>ldapsearch -h [server_name] -p [port] -s sub -b
    "ou=people,ou=foo,o=bar,c=com" "(id=123)"</p>
  </blockquote>
  
  <p>How the result looks like:</p>
  
  <blockquote>
    <p>id: 123</p>
    
    <p>name: John </p>
    
    <p>firstname: BAKER</p>
    
    <p>grouplist: cn=GROUP1.COM,cn=GROUPS,ou=FOO,o=BAR,c=COM</p>
    
    <p>grouplist: cn=GROUP2.COM,cn=GROUPS,ou=FOO,o=BAR,c=COM</p>
  </blockquote>
  
  <p>I use the LdapTemplate implementation of Spring. It works fine, but how can I handle results when they have multiple attributes with the same name (see above 'grouplist')? I tried to use the IncrementalAttributesMapper, but I didn't get it to work. </p>
  
  <pre><code>public MyUser getUser(String userId) {
     LdapQuery searchQuery = LdapQueryBuilder.query()
                  .base("ou=people,ou=foo,o=bar,c=com")
                  .searchScope(SearchScope.SUBTREE)
                  .filter(new EqualsFilter("id", userId));
  
     return ldapTemplate.search(searchQuery, getUserAttributesMapper());
  }
  
  public static AttributesMapper getUserAttributesMapper() {
          return attributes -&gt; {
  
              IncrementalAttributesMapper groupAttributesMapper = new DefaultIncrementalAttributesMapper("grouplist");
  
              MyUser myUser = MyUser.builder()
                   .id(attributes.get("id").get().toString())
                   .name(attributes.get("name").get().toString())
                   .firstname(attributes.get("firstname").get().toString())
                   .groupIds(groupAttributesMapper.getValues("cn"))
                   .build();
  
              return myUser;
          };
      }
  </code></pre>
  
  <p>When I try to read the attribute as follows:</p>
  
  <pre><code>attributes.get("grouplist").get().toString()
  </code></pre>
  
  <p>I get only the first group:</p>
  
  <blockquote>
    <p>grouplist: cn=GROUP1.COM,cn=GROUPS,ou=FOO,o=BAR,c=COM</p>
  </blockquote>
  
  <p>Thanks in advance for your support!</p>