You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2021/01/07 16:46:02 UTC
[camel] 01/01: make use of HashSet#contains instead of streaming +
regex which is slower
This is an automated email from the ASF dual-hosted git repository.
bvahdat pushed a commit to branch sensitive-utils
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1a539a8cf5093788d9e38cdab4273452483f8cb3
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Thu Jan 7 17:45:42 2021 +0100
make use of HashSet#contains instead of streaming + regex which is slower
---
.../src/main/java/org/apache/camel/util/SensitiveUtils.java | 9 ++++++---
.../src/test/java/org/apache/camel/util/SensitiveUtilsTest.java | 2 +-
2 files changed, 7 insertions(+), 4 deletions(-)
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
index 9854fec..ae7691f 100644
--- 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
@@ -18,17 +18,20 @@
package org.apache.camel.util;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Locale;
+import java.util.Set;
public final class SensitiveUtils {
- public static final String SENSITIVE_KEYS
- = "passphrase|password|secretkey|accesstoken|clientsecret|authorizationtoken|sasljaasconfig|accesskey";
+ public static final Set<String> SENSITIVE_KEYS = new HashSet<>(
+ Arrays.asList("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));
+ return SENSITIVE_KEYS.contains(text.toLowerCase(Locale.ENGLISH));
}
}
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
index 08fd28e..90ace7f 100644
--- 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
@@ -26,7 +26,7 @@ class SensitiveUtilsTest {
@Test
void testContainsSensitive() {
assertTrue(SensitiveUtils.containsSensitive("accessKey"));
- assertTrue(SensitiveUtils.containsSensitive("accesskey"));
+ assertTrue(SensitiveUtils.containsSensitive("passphrase"));
}
}