diff --git a/core/src/main/java/org/springframework/ldap/core/LdapOperations.java b/core/src/main/java/org/springframework/ldap/core/LdapOperations.java index 38d5e87f7e..c435143e79 100644 --- a/core/src/main/java/org/springframework/ldap/core/LdapOperations.java +++ b/core/src/main/java/org/springframework/ldap/core/LdapOperations.java @@ -1775,6 +1775,21 @@ boolean authenticate(String base, String filter, String password, */ List findAll(Class clazz); + /** + * Find all entries in the LDAP directory of a given type. The referenced class must have object-directory mapping metadata + * specified using {@link org.springframework.ldap.odm.annotations.Entry} and associated annotations. + * + * @param The Java type to return + * @param base The root of the sub-tree at which to begin the search. + * @param clazz The Java type to return + * @return All entries that are of the type represented by the given + * Java class + * + * @throws org.springframework.ldap.NamingException on error. + * @since 2.0 + */ + List findAll(Name base, Class clazz); + /** * Find all entries in the LDAP directory of a given type. The referenced class must have object-directory mapping metadata * specified using {@link org.springframework.ldap.odm.annotations.Entry} and associated annotations. diff --git a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java index f149165d03..2f75692ffe 100644 --- a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java +++ b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java @@ -1812,10 +1812,19 @@ public List findAll(Name base, SearchControls searchControls, final Class @Override public List findAll(Class clazz) { return findAll(LdapUtils.emptyLdapName(), - getDefaultSearchControls(defaultSearchScope, RETURN_OBJ_FLAG, ALL_ATTRIBUTES), clazz); } + /** + * {@inheritDoc} + */ + @Override + public List findAll(Name base, Class clazz) { + return findAll(base, + getDefaultSearchControls(defaultSearchScope, RETURN_OBJ_FLAG, ALL_ATTRIBUTES), + clazz); + } + /** * {@inheritDoc} */ diff --git a/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java b/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java index 6926b9420f..7389803eb8 100644 --- a/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java +++ b/core/src/main/java/org/springframework/ldap/repository/support/QueryDslLdapQuery.java @@ -21,7 +21,9 @@ import com.mysema.query.support.QueryMixin; import com.mysema.query.types.EntityPath; import com.mysema.query.types.Predicate; + import org.springframework.ldap.core.LdapOperations; +import org.springframework.ldap.odm.annotations.Entry; import org.springframework.ldap.query.LdapQuery; import java.util.List; @@ -69,7 +71,8 @@ public K uniqueResult() { } LdapQuery buildQuery() { - return query().filter(filterGenerator.handle(queryMixin.getMetadata().getWhere())); + String base = clazz.getAnnotation(Entry.class).base(); + return query().base(base).filter(filterGenerator.handle(queryMixin.getMetadata().getWhere())); } - + } diff --git a/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java b/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java index d17b2af874..3f7b930d17 100644 --- a/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java +++ b/core/src/main/java/org/springframework/ldap/repository/support/SimpleLdapRepository.java @@ -22,18 +22,22 @@ import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; import org.springframework.ldap.filter.Filter; +import org.springframework.ldap.odm.annotations.Entry; import org.springframework.ldap.odm.core.ObjectDirectoryMapper; import org.springframework.ldap.query.LdapQuery; import org.springframework.ldap.repository.LdapRepository; +import org.springframework.ldap.support.LdapUtils; import org.springframework.util.Assert; import javax.naming.Name; + import java.util.Iterator; import java.util.LinkedList; import java.util.List; import static org.springframework.ldap.query.LdapQueryBuilder.query; + /** * Base repository implementation for LDAP. * @@ -137,7 +141,8 @@ public boolean exists(Name name) { @Override public List findAll() { - return ldapOperations.findAll(clazz); + String base = clazz.getAnnotation(Entry.class).base(); + return ldapOperations.findAll(LdapUtils.newLdapName(base), clazz); } @Override