From b51817b1c577e6fe0680d2536c12b92fad209880 Mon Sep 17 00:00:00 2001 From: Michel Weber Date: Wed, 20 Sep 2023 14:17:26 +0200 Subject: [PATCH] Add utility methods to LdapOperations with LdapQuery and DirContextProcessor --- .../ldap/core/LdapOperations.java | 47 +++++++++++++++++++ .../ldap/core/LdapTemplate.java | 21 +++++++++ 2 files changed, 68 insertions(+) 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 b03fb7475..bb10ee6db 100644 --- a/core/src/main/java/org/springframework/ldap/core/LdapOperations.java +++ b/core/src/main/java/org/springframework/ldap/core/LdapOperations.java @@ -1508,6 +1508,53 @@ boolean authenticate(String base, String filter, String password, AuthenticatedL */ List search(LdapQuery query, AttributesMapper mapper); + /** + * Perform a search with parameters from the specified LdapQuery. All found objects + * will be supplied to the NameClassPairCallbackHandler for processing. + * @param query the LDAP query specification. + * @param callbackHandler the NameClassPairCallbackHandler to supply all + * found entries to. + * @param processor DirContextProcessor for custom pre- and + * post-processing. + * @throws NamingException if any error occurs. + * @since 2.0 + * @see org.springframework.ldap.query.LdapQueryBuilder + * @see org.springframework.ldap.core.support.CountNameClassPairCallbackHandler + */ + void search(LdapQuery query, NameClassPairCallbackHandler callbackHandler, DirContextProcessor processor); + + /** + * Perform a search with parameters from the specified LdapQuery. All found objects + * will be supplied to the ContextMapper for processing, and all returned + * objects will be collected in a list to be returned. + * @param query the LDAP query specification. + * @param mapper the ContextMapper to supply all found entries to. + * @param processor DirContextProcessor for custom pre- and + * post-processing. + * @return a List containing all entries received from the + * ContextMapper. + * @throws NamingException if any error occurs. + * @since 2.0 + * @see org.springframework.ldap.query.LdapQueryBuilder + */ + List search(LdapQuery query, ContextMapper mapper, DirContextProcessor processor); + + /** + * Perform a search with parameters from the specified LdapQuery. The Attributes of + * the found entries will be supplied to the AttributesMapper for + * processing, and all returned objects will be collected in a list to be returned. + * @param query the LDAP query specification. + * @param mapper the Attributes to supply all found Attributes to. + * @param processor DirContextProcessor for custom pre- and + * post-processing. + * @return a List containing all entries received from the + * Attributes. + * @throws NamingException if any error occurs. + * @since 2.0 + * @see org.springframework.ldap.query.LdapQueryBuilder + */ + List search(LdapQuery query, AttributesMapper mapper, DirContextProcessor processor); + /** * Perform a search for a unique entry matching the specified LDAP query and return * the found entry as a DirContextOperation instance. If no entry is found or if there 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 766f15598..474dceea1 100644 --- a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java +++ b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java @@ -1537,6 +1537,27 @@ public List search(LdapQuery query, AttributesMapper mapper) { return search(query.base(), query.filter().encode(), searchControls, mapper); } + @Override + public void search(LdapQuery query, NameClassPairCallbackHandler callbackHandler, DirContextProcessor processor) { + SearchControls searchControls = searchControlsForQuery(query, DONT_RETURN_OBJ_FLAG); + + search(query.base(), query.filter().encode(), searchControls, callbackHandler, processor); + } + + @Override + public List search(LdapQuery query, ContextMapper mapper, DirContextProcessor processor) { + SearchControls searchControls = searchControlsForQuery(query, DONT_RETURN_OBJ_FLAG); + + return search(query.base(), query.filter().encode(), searchControls, mapper, processor); + } + + @Override + public List search(LdapQuery query, AttributesMapper mapper, DirContextProcessor processor) { + SearchControls searchControls = searchControlsForQuery(query, DONT_RETURN_OBJ_FLAG); + + return search(query.base(), query.filter().encode(), searchControls, mapper, processor); + } + /** * {@inheritDoc} */