@Test public void findOneByAttribute() { final SocialPerson socialPerson = personRepo.findOneByAttribute("mail", "atang.sutisna.87@gmail.com"); assertNotNull(socialPerson); log.debug("We found 1 socialPerson : {}", socialPerson); }
@Override public T findOneByAttribute(String attribute, String value) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String filter = "(&(objectClass=*)(" + attribute + "=" + value + "))"; log.debug("Searching LDAP {} filter: {}", baseDn, filter); try { final Entry entry = withConnection(new Function<LdapConnection, Entry>() { @Override @Nullable public Entry apply(@Nullable LdapConnection conn) { try { List<Entry> entries = LdapUtils.asList(conn.search(baseDn, filter, SearchScope.ONELEVEL)); return Iterables.getOnlyElement(entries, null); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); if (entry != null) { log.debug("LDAP search {} filter {} returned {}", baseDn, filter, entry.getDn() ); final T entity = mapper.fromEntry(entry, entityClass); return entity; } else { log.debug("LDAP search {} filter {} returned nothing", baseDn, filter); return null; } } 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 T findOneByAttribute(String attribute, String value) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String filter = "(&(objectClass=*)(" + attribute + "=" + value + "))"; log.debug("Searching LDAP {} filter: {}", baseDn, filter); try { final Entry entry = withConnection(new Function<LdapConnection, Entry>() { @Override @Nullable public Entry apply(@Nullable LdapConnection conn) { try { List<Entry> entries = LdapUtils.asList(conn.search(baseDn, filter, SearchScope.ONELEVEL)); return Iterables.getOnlyElement(entries, null); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); if (entry != null) { log.debug("LDAP search {} filter {} returned {}", baseDn, filter, entry.getDn() ); final T entity = mapper.fromEntry(entry, entityClass); return entity; } else { log.debug("LDAP search {} filter {} returned nothing", baseDn, filter); return null; } } 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 T findOneByAttribute(String attribute, String value) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String filter = "(&(objectClass=*)(" + attribute + "=" + value + "))"; log.debug("Searching LDAP {} filter: {}", baseDn, filter); try { final Entry entry = withConnection(new Function<LdapConnection, Entry>() { @Override @Nullable public Entry apply(@Nullable LdapConnection conn) { try { List<Entry> entries = LdapUtils.asList(conn.search(baseDn, filter, SearchScope.ONELEVEL)); return Iterables.getOnlyElement(entries, null); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); if (entry != null) { log.debug("LDAP search {} filter {} returned {}", baseDn, filter, entry.getDn() ); final T entity = mapper.fromEntry(entry, entityClass); return entity; } else { log.debug("LDAP search {} filter {} returned nothing", baseDn, filter); return null; } } 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 T findOneByAttribute(String attribute, String value) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String filter = "(&(objectClass=*)(" + attribute + "=" + value + "))"; log.debug("Searching LDAP {} filter: {}", baseDn, filter); try { final Entry entry = withConnection(new Function<LdapConnection, Entry>() { @Override @Nullable public Entry apply(@Nullable LdapConnection conn) { try { List<Entry> entries = LdapUtils.asList(conn.search(baseDn, filter, SearchScope.ONELEVEL)); return Iterables.getOnlyElement(entries, null); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); if (entry != null) { log.debug("LDAP search {} filter {} returned {}", baseDn, filter, entry.getDn() ); final T entity = mapper.fromEntry(entry, entityClass); return entity; } else { log.debug("LDAP search {} filter {} returned nothing", baseDn, filter); return null; } } 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 T findOneByAttribute(String attribute, String value) { final String primaryObjectClass = mapper.getMapping(entityClass).getPrimaryObjectClass(); final String filter = "(&(objectClass=*)(" + attribute + "=" + value + "))"; log.debug("Searching LDAP {} filter: {}", baseDn, filter); try { final Entry entry = withConnection(new Function<LdapConnection, Entry>() { @Override @Nullable public Entry apply(@Nullable LdapConnection conn) { try { List<Entry> entries = LdapUtils.asList(conn.search(baseDn, filter, SearchScope.ONELEVEL)); return Iterables.getOnlyElement(entries, null); } catch (LdapException e) { Throwables.propagate(e); return null; } } }); if (entry != null) { log.debug("LDAP search {} filter {} returned {}", baseDn, filter, entry.getDn() ); final T entity = mapper.fromEntry(entry, entityClass); return entity; } else { log.debug("LDAP search {} filter {} returned nothing", baseDn, filter); return null; } } 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);  }