@Test public void findAllByMultipleFilter() { final String filter = "(|(cn=*ang*)(mobile=*0856*))"; final List<SocialPerson> people = personRepo.findAllByFilter(filter); log.info("User by filter has {} records", people.size()); }
@Override public List<T> findAllByFilter(String filter) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String realFilter = String.format("(&(objectClass=*)%s)", filter); log.debug("Searching LDAP {} filter: {}", baseDn, realFilter); try { final List<Entry> entries = withConnection(new Function<LdapConnection, List<Entry>>() { @Override @Nullable public List<Entry> apply(@Nullable LdapConnection conn) { try { return LdapUtils.asList( conn.search(baseDn, realFilter, SearchScope.ONELEVEL) ); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); final List<Dn> limitedEntryDns = FluentIterable.from(entries).transform(new EntryDnFunction()).limit(10).toList(); log.debug("LDAP search {} filter {} returned {} entries: {}", baseDn, filter, entries.size(), limitedEntryDns); final List<T> entities = Lists.transform(entries, new EntryToEntity()); return entities; } catch (Exception e) { throw new LdapRepositoryException(e, "Error searching LDAP in %s filter %s", baseDn, filter); } }
PooledLdapRepository extends CrudRepositoryBase<T, String> implements LdapRepository<T> { @Override public List<T> findAllByFilter(String filter) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String realFilter = String.format("(&(objectClass=*)%s)", filter); log.debug("Searching LDAP {} filter: {}", baseDn, realFilter); try { final List<Entry> entries = withConnection(new Function<LdapConnection, List<Entry>>() { @Override @Nullable public List<Entry> apply(@Nullable LdapConnection conn) { try { return LdapUtils.asList( conn.search(baseDn, realFilter, SearchScope.ONELEVEL) ); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); final List<Dn> limitedEntryDns = FluentIterable.from(entries).transform(new EntryDnFunction()).limit(10).toList(); log.debug("LDAP search {} filter {} returned {} entries: {}", baseDn, filter, entries.size(), limitedEntryDns); final List<T> entities = Lists.transform(entries, new EntryToEntity()); return entities; } catch (Exception e) { throw new LdapRepositoryException(e, "Error searching LDAP in %s filter %s", baseDn, filter); } } }
PooledLdapRepository extends CrudRepositoryBase<T, String> implements LdapRepository<T> { @Override public List<T> findAllByFilter(String filter) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String realFilter = String.format("(&(objectClass=*)%s)", filter); log.debug("Searching LDAP {} filter: {}", baseDn, realFilter); try { final List<Entry> entries = withConnection(new Function<LdapConnection, List<Entry>>() { @Override @Nullable public List<Entry> apply(@Nullable LdapConnection conn) { try { return LdapUtils.asList( conn.search(baseDn, realFilter, SearchScope.ONELEVEL) ); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); final List<Dn> limitedEntryDns = FluentIterable.from(entries).transform(new EntryDnFunction()).limit(10).toList(); log.debug("LDAP search {} filter {} returned {} entries: {}", baseDn, filter, entries.size(), limitedEntryDns); final List<T> entities = Lists.transform(entries, new EntryToEntity()); return entities; } catch (Exception e) { throw new LdapRepositoryException(e, "Error searching LDAP in %s filter %s", baseDn, filter); } } PooledLdapRepository(final Class<? extends T> entityClass, final ObjectPool<LdapConnection> pool, final String baseDn); }
PooledLdapRepository extends CrudRepositoryBase<T, String> implements LdapRepository<T> { @Override public List<T> findAllByFilter(String filter) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String realFilter = String.format("(&(objectClass=*)%s)", filter); log.debug("Searching LDAP {} filter: {}", baseDn, realFilter); try { final List<Entry> entries = withConnection(new Function<LdapConnection, List<Entry>>() { @Override @Nullable public List<Entry> apply(@Nullable LdapConnection conn) { try { return LdapUtils.asList( conn.search(baseDn, realFilter, SearchScope.ONELEVEL) ); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); final List<Dn> limitedEntryDns = FluentIterable.from(entries).transform(new EntryDnFunction()).limit(10).toList(); log.debug("LDAP search {} filter {} returned {} entries: {}", baseDn, filter, entries.size(), limitedEntryDns); final List<T> entities = Lists.transform(entries, new EntryToEntity()); return entities; } catch (Exception e) { throw new LdapRepositoryException(e, "Error searching LDAP in %s filter %s", baseDn, filter); } } PooledLdapRepository(final Class<? extends T> entityClass, final ObjectPool<LdapConnection> pool, final String baseDn); @Override @Deprecated void init(); @Override S add(S entity); @Override @Nonnull T modify(final T entity); @Override S modify(String id, final S entity); @Override boolean delete(String id); @SuppressWarnings("unchecked") @Override U findOne(String id); @Override String toDn(String id); @Override T findOneByAttribute(String attribute, String value); @Override List<String> findIdsByAttribute(String attribute, String value); @Override List<T> findAll(); @Override String getBaseDn(); @Override Class<? extends T> getEntityClass(); @Override LdapMapper<T> getMapper(); ObjectPool<LdapConnection> getPool(); @Override boolean exists(@Nullable String id); @Override List<T> search(@Nullable String searchText); @Override boolean existsByAttribute(String attribute, String value); @Override List<T> findAllByFilter(String filter); @Override long count(); @Override long countByAttribute(String attribute, String value); @Override Page<T> findAll(final Pageable pageable); @Override List<String> findIdsByFilter(String filter); }
PooledLdapRepository extends CrudRepositoryBase<T, String> implements LdapRepository<T> { @Override public List<T> findAllByFilter(String filter) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String realFilter = String.format("(&(objectClass=*)%s)", filter); log.debug("Searching LDAP {} filter: {}", baseDn, realFilter); try { final List<Entry> entries = withConnection(new Function<LdapConnection, List<Entry>>() { @Override @Nullable public List<Entry> apply(@Nullable LdapConnection conn) { try { return LdapUtils.asList( conn.search(baseDn, realFilter, SearchScope.ONELEVEL) ); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); final List<Dn> limitedEntryDns = FluentIterable.from(entries).transform(new EntryDnFunction()).limit(10).toList(); log.debug("LDAP search {} filter {} returned {} entries: {}", baseDn, filter, entries.size(), limitedEntryDns); final List<T> entities = Lists.transform(entries, new EntryToEntity()); return entities; } catch (Exception e) { throw new LdapRepositoryException(e, "Error searching LDAP in %s filter %s", baseDn, filter); } } PooledLdapRepository(final Class<? extends T> entityClass, final ObjectPool<LdapConnection> pool, final String baseDn); @Override @Deprecated void init(); @Override S add(S entity); @Override @Nonnull T modify(final T entity); @Override S modify(String id, final S entity); @Override boolean delete(String id); @SuppressWarnings("unchecked") @Override U findOne(String id); @Override String toDn(String id); @Override T findOneByAttribute(String attribute, String value); @Override List<String> findIdsByAttribute(String attribute, String value); @Override List<T> findAll(); @Override String getBaseDn(); @Override Class<? extends T> getEntityClass(); @Override LdapMapper<T> getMapper(); ObjectPool<LdapConnection> getPool(); @Override boolean exists(@Nullable String id); @Override List<T> search(@Nullable String searchText); @Override boolean existsByAttribute(String attribute, String value); @Override List<T> findAllByFilter(String filter); @Override long count(); @Override long countByAttribute(String attribute, String value); @Override Page<T> findAll(final Pageable pageable); @Override List<String> findIdsByFilter(String filter);  }