summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smokowski <kevin.smokowski@att.com>2020-08-11 20:07:22 +0000
committerKevin Smokowski <kevin.smokowski@att.com>2020-08-11 20:34:12 +0000
commit45b5a460fdcec757f4482d69009b87da34728670 (patch)
tree746e2f4ca7165f28325d3c19f31cc90161a78153
parente8f6c9650e8a082a3302dc182229e94962fea0f4 (diff)
add new print methods
create filtered print method for svclogic context Issue-ID: CCSDK-2643 Change-Id: I59261b1e581130d0fbe7d6735f96ee4c6e90ae75 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java91
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java18
-rw-r--r--sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java1
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java24
4 files changed, 133 insertions, 1 deletions
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java
new file mode 100644
index 000000000..d12729c42
--- /dev/null
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SecurePrinter.java
@@ -0,0 +1,91 @@
+
+package org.onap.ccsdk.sli.core.sli;
+
+import java.util.HashMap;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SecurePrinter {
+ private static final Logger LOG = LoggerFactory.getLogger(SecurePrinter.class);
+ private static final String DEFAULT_FILTER = "password,pass,pswd";
+ private static final String REDACTED = "***REDACTED***";
+ private static final String FILTER_PROPERTY = "NODE_STRING_FILTER";
+ private static String[] filterArray;
+
+ public SecurePrinter() {
+ String filterProperty = System.getProperty(FILTER_PROPERTY);
+ if (filterProperty != null && !filterProperty.isEmpty() && filterProperty.contains(",")) {
+ filterArray = filterProperty.split(",");
+ } else {
+ filterArray = DEFAULT_FILTER.split(",");
+ }
+ }
+
+ private String filterValue(String key, String value) {
+ String normalizedKey = key.toLowerCase();
+ for (String restrictedKey : filterArray) {
+ if (normalizedKey.contains(restrictedKey)) {
+ return REDACTED;
+ }
+ }
+ return value;
+ }
+
+ public void printAttributes(HashMap<String, String> attributes) {
+ if (LOG.isDebugEnabled()) {
+ for (Entry<String, String> attribute : attributes.entrySet()) {
+ String value = filterValue(attribute.getKey(), attribute.getValue());
+ LOG.debug(attribute.getKey() + " = " + value);
+ }
+ }
+ }
+
+ public void printAttributes(HashMap<String, String> attributes, String subpath) {
+ if (LOG.isDebugEnabled()) {
+ for (Entry<String, String> attribute : attributes.entrySet()) {
+ if (attribute.getKey().startsWith(subpath)) {
+ String value = filterValue(attribute.getKey(), attribute.getValue());
+ LOG.debug(attribute.getKey() + " = " + value);
+ }
+ }
+ }
+ }
+
+ public void printProperties(Properties props) {
+ if (LOG.isDebugEnabled()) {
+ try {
+ for (Entry<Object, Object> property : props.entrySet()) {
+ String keyString = (String) property.getKey();
+ String valueString = (String) property.getValue();
+ String value = filterValue(keyString, valueString);
+ LOG.debug(keyString + " = " + value);
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to print properties", e);
+ }
+ }
+ }
+
+ public void printProperties(Properties props, String subpath) {
+ if (LOG.isDebugEnabled()) {
+ try {
+ for (Entry<Object, Object> property : props.entrySet()) {
+ String keyString = (String) property.getKey();
+ if (keyString.startsWith(subpath)) {
+ String valueString = (String) property.getValue();
+ String value = filterValue(keyString, valueString);
+ LOG.debug(keyString + " = " + value);
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to print properties", e);
+ }
+ }
+ }
+
+}
+
+
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
index f07f71f10..129c08526 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
@@ -36,7 +36,7 @@ import org.w3c.dom.Text;
public class SvcLogicContext {
private static final Logger LOG = LoggerFactory.getLogger(SvcLogicContext.class);
-
+ private final SecurePrinter securePrinter = new SecurePrinter();
public static final String CTX_NULL_VALUE="";
private static final String LENGTH="_length";
@@ -415,4 +415,20 @@ public class SvcLogicContext {
return (root.toString());
}
+
+ public void printProperties(Properties props) {
+ securePrinter.printProperties(props);
+ }
+
+ public void printAttributes() {
+ securePrinter.printAttributes(attributes);
+ }
+
+ public void printProperties(Properties props, String subpath) {
+ securePrinter.printProperties(props, subpath);
+ }
+
+ public void printAttributes(String subpath) {
+ securePrinter.printAttributes(attributes, subpath);
+ }
}
diff --git a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java
index 7f2674e51..b23662a6c 100644
--- a/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java
+++ b/sli/provider-base/src/main/java/org/onap/ccsdk/sli/core/sli/provider/base/ExecuteNodeExecutor.java
@@ -66,6 +66,7 @@ public class ExecuteNodeExecutor extends AbstractSvcLogicNodeExecutor {
Method pluginMethod = null;
try {
+ LOG.debug("executing method {} on plugin {}", methodName, pluginName);
pluginMethod = pluginClass.getMethod(methodName, Map.class, SvcLogicContext.class);
} catch (NoSuchMethodException e) {
LOG.error(pluginErrorMessage, e);
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
index 816bb5dff..2edb36dc4 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
@@ -733,6 +733,30 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
}
+ public static void logContextProperties(Map<String, String> parameters, SvcLogicContext ctx)
+ throws SvcLogicException {
+ if (LOG.isTraceEnabled()) {
+ String subpath = parameters.get("subpath");
+ if (subpath != null && !subpath.isEmpty()) {
+ ctx.printProperties(ctx.toProperties(), subpath);
+ } else {
+ ctx.printProperties(ctx.toProperties());
+ }
+ }
+ }
+
+ public static void logContextAttributes(Map<String, String> parameters, SvcLogicContext ctx)
+ throws SvcLogicException {
+ if (LOG.isTraceEnabled()) {
+ String subpath = parameters.get("subpath");
+ if (subpath != null && !subpath.isEmpty()) {
+ ctx.printAttributes(subpath);
+ } else {
+ ctx.printAttributes();
+ }
+ }
+ }
+
/**
* Checks context memory for a set of required parameters
* Every parameter aside from prefix will be treated as mandatory