spring-ldap icon indicating copy to clipboard operation
spring-ldap copied to clipboard

'in' or 'anyOf' filter criteria

Open ihr opened this issue 10 years ago • 4 comments

it will be nice to have a 'in' or 'anyOf' filter criteria which is basically: (| (...K1...) (...K2...))

ihr avatar Jan 06 '15 14:01 ihr

You can do this with the LdapQueryBuilder:

LdapQueryBuilder.where("cn").is("John Doe")
  .or("cn").is("Jane Doe")
  .or("cn").is("Something Else")

You can also accomplish this with the legacy filter classes, i.e. OrFilter; just add more conditions: http://docs.spring.io/spring-ldap/docs/current/apidocs/index.html?org/springframework/ldap/filter/OrFilter.html

marthursson avatar Jan 07 '15 07:01 marthursson

Hi, that's exactly what I'm doing. The thing is that if I have a list or array of values I have to always perform the same procedure:

ContainerCriteria containerCriteria = LdapQueryBuilder.query().where("cn").is(values.get(FIRST_ELEMENT))

for(String value : values.subList(FIRST_ELEMENT, values.size())) {
containerCriteria = containerCriteria.or(keyAttribute).is(value);
}

This can be provided by the library itself

ihr avatar Jan 07 '15 10:01 ihr

I see. I agree that something like the below would be more efficient:

LdapQueryBuilder.query().where("cn").in(valuesCollection)

and/or

LdapQueryBuilder.query().where("cn").in(value1, value2, value3)

marthursson avatar Jan 07 '15 10:01 marthursson

Exactly! The same can be done for & operator (&(...K1...)(...K2...)...). I named our method allOf.

ihr avatar Jan 07 '15 10:01 ihr