use of org.springframework.ldap.LimitExceededException in project gravitee-management-rest-api by gravitee-io.
the class LdapIdentityLookup method search.
@Override
public Collection<User> search(String query) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
Filter classFilter = new EqualsFilter("objectclass", environment.getProperty("user-search-objectclass", LDAP_DEFAULT_OBJECT_CLASS));
Filter queryFilter = new OrFilter().or(new WhitespaceWildcardsFilter(LDAP_ATTRIBUTE_COMMONNAME, query)).or(new EqualsFilter(LDAP_ATTRIBUTE_USERID, query));
LdapQuery ldapQuery = LdapQueryBuilder.query().base(baseDn).countLimit(20).timeLimit(5000).searchScope(SearchScope.SUBTREE).attributes(LDAP_ATTRIBUTE_GIVENNAME, LDAP_ATTRIBUTE_SURNAME, LDAP_ATTRIBUTE_MAIL, LDAP_ATTRIBUTE_DISPLAYNAME).filter(new AndFilter().and(classFilter).and(queryFilter));
return ldapTemplate.search(ldapQuery, USER_CONTEXT_MAPPER);
} catch (LimitExceededException lee) {
LOGGER.info("Too much results while searching for [" + query + "]. Returns an empty list.");
return Collections.emptyList();
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
Aggregations