You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/01/06 20:19:22 UTC

[camel] branch master updated: Make the sensitive string check easier to reuse so that we can eval and filter them (#4834)

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

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new f7b12e8  Make the sensitive string check easier to reuse so that we can eval and filter them (#4834)
f7b12e8 is described below

commit f7b12e8f0980e07830b2ad261c2349adc47d056c
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Wed Jan 6 21:18:49 2021 +0100

    Make the sensitive string check easier to reuse so that we can eval and filter them (#4834)
---
 .../org/apache/camel/main/BaseMainSupport.java     | 12 ++------
 .../java/org/apache/camel/util/SensitiveUtils.java | 34 ++++++++++++++++++++++
 .../org/apache/camel/util/SensitiveUtilsTest.java  | 32 ++++++++++++++++++++
 3 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 62bf76f..1eb9f1d 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -21,7 +21,6 @@ import java.io.FileInputStream;
 import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -62,6 +61,7 @@ import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.OrderedProperties;
 import org.apache.camel.util.PropertiesHelper;
+import org.apache.camel.util.SensitiveUtils;
 import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -87,9 +87,6 @@ public abstract class BaseMainSupport extends BaseService {
 
     private static final Logger LOG = LoggerFactory.getLogger(BaseMainSupport.class);
 
-    private static final String SENSITIVE_KEYS
-            = "passphrase|password|secretkey|accesstoken|clientsecret|authorizationtoken|sasljaasconfig";
-
     protected volatile CamelContext camelContext;
 
     protected final List<MainListener> listeners = new ArrayList<>();
@@ -434,9 +431,7 @@ public abstract class BaseMainSupport extends BaseService {
         if (mainConfigurationProperties.isAutoConfigurationLogSummary() && !autoConfiguredProperties.isEmpty()) {
             LOG.info("Auto-configuration summary:");
             autoConfiguredProperties.forEach((k, v) -> {
-                boolean sensitive
-                        = Arrays.stream(SENSITIVE_KEYS.split("\\|")).anyMatch(s -> k.toLowerCase(Locale.ENGLISH).contains(s));
-                if (sensitive) {
+                if (SensitiveUtils.containsSensitive(k)) {
                     LOG.info("\t{}=xxxxxx", k);
                 } else {
                     LOG.info("\t{}={}", k, v);
@@ -1201,8 +1196,7 @@ public abstract class BaseMainSupport extends BaseService {
             if (mainConfigurationProperties.isAutoConfigurationLogSummary() && !autoConfiguredProperties.isEmpty()) {
                 LOG.info("Auto-configuration component {} summary:", name);
                 autoConfiguredProperties.forEach((k, v) -> {
-                    boolean sensitive = SENSITIVE_KEYS.contains(k.toLowerCase(Locale.ENGLISH));
-                    if (sensitive) {
+                    if (SensitiveUtils.containsSensitive(k)) {
                         LOG.info("\t{}=xxxxxx", k);
                     } else {
                         LOG.info("\t{}={}", k, v);
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
new file mode 100644
index 0000000..9854fec
--- /dev/null
+++ b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
@@ -0,0 +1,34 @@
+/*
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.Locale;
+
+public final class SensitiveUtils {
+    public static final String SENSITIVE_KEYS
+            = "passphrase|password|secretkey|accesstoken|clientsecret|authorizationtoken|sasljaasconfig|accesskey";
+
+    private SensitiveUtils() {
+
+    }
+
+    public static boolean containsSensitive(String text) {
+        return Arrays.stream(SENSITIVE_KEYS.split("\\|")).anyMatch(s -> text.toLowerCase(Locale.ENGLISH).contains(s));
+    }
+}
diff --git a/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java b/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
new file mode 100644
index 0000000..08fd28e
--- /dev/null
+++ b/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class SensitiveUtilsTest {
+
+    @Test
+    void testContainsSensitive() {
+        assertTrue(SensitiveUtils.containsSensitive("accessKey"));
+        assertTrue(SensitiveUtils.containsSensitive("accesskey"));
+    }
+
+}