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/12/14 10:11:31 UTC

[camel] branch camel-3.14.x updated: CAMEL-18811: camel-ldap - InvalidSearchFilterException: invalid attribute description

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


The following commit(s) were added to refs/heads/camel-3.14.x by this push:
     new 42d458b8ca4 CAMEL-18811: camel-ldap - InvalidSearchFilterException: invalid attribute description
42d458b8ca4 is described below

commit 42d458b8ca4ce3096ffa1137eaafdc176dcea551
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 14 11:10:23 2022 +0100

    CAMEL-18811: camel-ldap - InvalidSearchFilterException: invalid attribute description
---
 .../apache/camel/component/ldap/LdapHelper.java    | 68 ++++++++++++++++++++++
 .../apache/camel/component/ldap/LdapProducer.java  | 44 --------------
 2 files changed, 68 insertions(+), 44 deletions(-)

diff --git a/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapHelper.java b/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapHelper.java
new file mode 100644
index 00000000000..47ae3dd7b5a
--- /dev/null
+++ b/components/camel-ldap/src/main/java/org/apache/camel/component/ldap/LdapHelper.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.ldap;
+
+public final class LdapHelper {
+
+    private LdapHelper() {
+    }
+
+    /**
+     * Given an LDAP search string, returns the string with certain characters escaped according to RFC 2254 guidelines.
+     * The character mapping is as follows:
+     * <ul>
+     * <li>* = \2a</li>
+     * <li>( = \28</li>
+     * <li>) = \29</li>
+     * <li>\ = \5c</li>
+     * <li>\0 = \00</li>
+     * </ul>
+     * 
+     * @param  filter string to escape according to RFC 2254 guidelines
+     * @return        String the escaped/encoded result
+     */
+    public static 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();
+    }
+}
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 d6384c0b6bb..92864e7292b 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
@@ -70,10 +70,6 @@ public class LdapProducer extends DefaultProducer {
     @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 {
@@ -174,44 +170,4 @@ 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();
-    }
-
 }