Search code examples
javaldapldif

In an LDAP search filter, is it possible to ask for the 1st, 2nd, nth, or last value of a multi-valued field?


Using a search filter, is it possible to retrieve the last value of a multi-valued field for an object e.g. the department field of the inetOrgPerson?

For instance, if my user cn=Alice has 2 values for department, can I somehow write a search filter that will return the last value only?

Thanks.


Solution

  • LDAPSearch filters are meant to find and filter LDAP entries. In the LDAP request, the list of attributes to retrieve is a separate parameter from the filter. An LDAP Extension (a Control) exists to specify to match and retrieve only matching values of a multi-valued attribute, specified in RFC 3876. This extension is not implemented in all LDAP directory services, nor in all LDAP clients.