You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/11/08 11:51:16 UTC

[camel] branch camel-3.14.x updated (e930575e85f -> c46cbcc6bee)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git


    from e930575e85f Regen for commit 14a14d8798889a29868f1c09ff3e2a4b12a6b800 (#8674)
     new c543ee1ebd6 CAMEL-18696: camel-ldap - Make filter a bit easier to use (#8687)
     new c46cbcc6bee CAMEL-18696: camel-ldap - Make filter a bit easier to use (#8687)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/component/ldap/LdapProducer.java  | 58 +++++++++++++++++++---
 1 file changed, 51 insertions(+), 7 deletions(-)


[camel] 01/02: CAMEL-18696: camel-ldap - Make filter a bit easier to use (#8687)

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c543ee1ebd632566618293f8e2d3fc2969198283
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 8 12:49:11 2022 +0100

    CAMEL-18696: camel-ldap - Make filter a bit easier to use (#8687)
---
 .../apache/camel/component/ldap/LdapProducer.java  | 65 +++++++++++++++++++---
 1 file changed, 58 insertions(+), 7 deletions(-)

diff --git a/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java b/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
index de085b2b3ae..f7dfd90a726 100644
--- a/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
+++ b/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
@@ -43,10 +43,10 @@ public class LdapProducer extends DefaultProducer {
 
     private static final Logger LOG = LoggerFactory.getLogger(LdapProducer.class);
 
-    private String remaining;
-    private SearchControls searchControls;
-    private String searchBase;
-    private Integer pageSize;
+    private final String remaining;
+    private final SearchControls searchControls;
+    private final String searchBase;
+    private final Integer pageSize;
 
     public LdapProducer(LdapEndpoint endpoint, String remaining, String base, int scope, Integer pageSize,
                         String returnedAttributes) {
@@ -59,17 +59,21 @@ public class LdapProducer extends DefaultProducer {
         this.searchControls = new SearchControls();
         this.searchControls.setSearchScope(scope);
         if (returnedAttributes != null) {
-            String returnedAtts[] = returnedAttributes.split(",");
+            String[] atts = returnedAttributes.split(",");
             if (LOG.isDebugEnabled()) {
-                LOG.debug("Setting returning Attributes to searchControls: {}", Arrays.toString(returnedAtts));
+                LOG.debug("Setting returning Attributes to searchControls: {}", Arrays.toString(atts));
             }
-            searchControls.setReturningAttributes(returnedAtts);
+            searchControls.setReturningAttributes(atts);
         }
     }
 
     @Override
     public void process(Exchange exchange) throws Exception {
         String filter = exchange.getIn().getBody(String.class);
+        if (filter != null) {
+            // filter must be LDAP escaped
+            filter = escapeFilter(filter);
+        }
         DirContext dirContext = getDirContext();
 
         try {
@@ -170,4 +174,51 @@ public class LdapProducer extends DefaultProducer {
         }
     }
 
+    /**
+     * Given an LDAP search string, returns the string with certain characters
+     * escaped according to RFC 2254 guidelines.
+     *
+     * The character mapping is as follows:
+     *     char -&gt;  Replacement
+     *    ---------------------------
+     *     *  -&gt; \2a
+     *     (  -&gt; \28
+     *     )  -&gt; \29
+     *     \  -&gt; \5c
+     *     \0 -&gt; \00
+     *
+     * @param filter string to escape according to RFC 2254 guidelines
+     * @return String the escaped/encoded result
+     */
+    private String escapeFilter(String filter) {
+        if (filter == null) {
+            return null;
+        }
+        StringBuilder buf = new StringBuilder(filter.length());
+        for (int i = 0; i < filter.length(); i++) {
+            char c = filter.charAt(i);
+            switch (c) {
+                case '\\':
+                    buf.append("\\5c");
+                    break;
+                case '*':
+                    buf.append("\\2a");
+                    break;
+                case '(':
+                    buf.append("\\28");
+                    break;
+                case ')':
+                    buf.append("\\29");
+                    break;
+                case '\0':
+                    buf.append("\\00");
+                    break;
+                default:
+                    buf.append(c);
+                    break;
+            }
+        }
+        return buf.toString();
+    }
+
 }


[camel] 02/02: CAMEL-18696: camel-ldap - Make filter a bit easier to use (#8687)

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c46cbcc6bee94ec631e7898b0c944cae98b4a071
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 8 12:49:57 2022 +0100

    CAMEL-18696: camel-ldap - Make filter a bit easier to use (#8687)
---
 .../org/apache/camel/component/ldap/LdapProducer.java   | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java b/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
index f7dfd90a726..d6384c0b6bb 100644
--- a/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
+++ b/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapProducer.java
@@ -175,20 +175,13 @@ public class LdapProducer extends DefaultProducer {
     }
 
     /**
-     * Given an LDAP search string, returns the string with certain characters
-     * escaped according to RFC 2254 guidelines.
+     * Given an LDAP search string, returns the string with certain characters escaped according to RFC 2254 guidelines.
      *
-     * The character mapping is as follows:
-     *     char -&gt;  Replacement
-     *    ---------------------------
-     *     *  -&gt; \2a
-     *     (  -&gt; \28
-     *     )  -&gt; \29
-     *     \  -&gt; \5c
-     *     \0 -&gt; \00
+     * The character mapping is as follows: char -&gt; Replacement --------------------------- * -&gt; \2a ( -&gt; \28 )
+     * -&gt; \29 \ -&gt; \5c \0 -&gt; \00
      *
-     * @param filter string to escape according to RFC 2254 guidelines
-     * @return String the escaped/encoded result
+     * @param  filter string to escape according to RFC 2254 guidelines
+     * @return        String the escaped/encoded result
      */
     private String escapeFilter(String filter) {
         if (filter == null) {