aboutsummaryrefslogtreecommitdiffstats
path: root/feature-mdc-filters
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2021-06-14 17:20:51 -0500
committerjhh <jorge.hernandez-herrero@att.com>2021-06-14 17:20:51 -0500
commit0945bc95ad1eb147c1ddf3d2069ad9a531838649 (patch)
treebe94e922aea3e58d97a5251597428c0a995bd04a /feature-mdc-filters
parented08c7f8d6d124cc3a6a42a5b630d549a5b34968 (diff)
Use re2j pattern for sonar vulnerabilities
Issue-ID: POLICY-3289 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Id6d58b5c8ac5f7715286f21274ccf5eea9155fd2
Diffstat (limited to 'feature-mdc-filters')
-rwxr-xr-xfeature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java b/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java
index b66c254a..4ebe18e1 100755
--- a/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java
+++ b/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java
@@ -1,8 +1,8 @@
/*
* ============LICENSE_START=======================================================
- * feature-mdc-filters
+ * ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,14 @@
package org.onap.policy.drools.mdc.filters;
-import com.att.aft.dme2.internal.apache.commons.lang3.StringUtils;
+import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,11 +35,13 @@ import org.slf4j.LoggerFactory;
public class MdcTopicFilter {
private static final Logger logger = LoggerFactory.getLogger(MdcTopicFilter.class);
+ private static final Pattern COMMA_SPACE_PAT = Pattern.compile("\\s*,\\s*");
+ private static final Pattern EQUAL_PAT = Pattern.compile("\\s*=\\s*");
public static final String MDC_KEY_ERROR = "mdcKey must be provided";
public static final String JSON_PATH_ERROR = "json path(s) must be provided";
- private Map<String, FilterRule> rules = new HashMap<>();
+ private final Map<String, FilterRule> rules = new HashMap<>();
@Getter
public static class FilterRule {
@@ -91,14 +94,14 @@ public class MdcTopicFilter {
}
protected MdcTopicFilter(String rawFilters) {
- for (String filter : rawFilters.split("\\s*,\\s*")) {
- FilterRule rule = createFilterRule(filter);
+ for (String filter : COMMA_SPACE_PAT.split(rawFilters)) {
+ var rule = createFilterRule(filter);
rules.put(rule.mdcKey, rule);
}
}
private FilterRule createFilterRule(String filter) {
- String[] filterKeyPaths = filter.split("\\s*=\\s*");
+ String[] filterKeyPaths = EQUAL_PAT.split(filter);
if (filterKeyPaths.length != 2) {
throw new IllegalArgumentException("could not parse filter rule");
}
@@ -165,7 +168,7 @@ public class MdcTopicFilter {
throw new IllegalArgumentException("a filter rule already exists for key: " + mdcKey);
}
- FilterRule rule = new FilterRule(mdcKey, paths);
+ var rule = new FilterRule(mdcKey, paths);
rules.put(mdcKey, rule);
return rule;
}