X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2FPropAccess.java;h=d6b8d56df2eb88343dd906df1ca3c3bd50b7dc73;hb=ff1417ff60baee231a28272f9a16ef2c9c8ea0a2;hp=8467c7c6b5369aca298a93c4964003e6188577b2;hpb=7e966914050e66219689001ff4ab601a49eef0ac;p=aaf%2Fauthz.git diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java index 8467c7c6..d6b8d56d 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java @@ -26,6 +26,9 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -35,6 +38,7 @@ import java.util.Properties; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfo; +import org.onap.aaf.cadi.util.Split; public class PropAccess implements Access { // Sonar says cannot be static... it's ok. not too many PropAccesses created. @@ -117,13 +121,21 @@ public class PropAccess implements Access { props.putAll(p); } - // Third, load any Chained Property Files - load(props.getProperty(Config.CADI_PROP_FILES)); - + // Preset LogLevel String sLevel = props.getProperty(Config.CADI_LOGLEVEL); if (sLevel!=null) { level=Level.valueOf(sLevel).maskOf(); } + + // Third, load any Chained Property Files + load(props.getProperty(Config.CADI_PROP_FILES)); + + if(sLevel==null) { // if LogLev wasn't set before, check again after Chained Load + sLevel = props.getProperty(Config.CADI_LOGLEVEL); + if (sLevel!=null) { + level=Level.valueOf(sLevel).maskOf(); + } + } // Setup local Symmetrical key encryption if (symm==null) { try { @@ -137,51 +149,42 @@ public class PropAccess implements Access { name = props.getProperty(Config.CADI_LOGNAME, name); - specialConversions(); - } - - private void specialConversions() { - // Critical - if no Security Protocols set, then set it. We'll just get messed up if not - if (props.get(Config.CADI_PROTOCOLS)==null) { - props.setProperty(Config.CADI_PROTOCOLS, SecurityInfo.HTTPS_PROTOCOLS_DEFAULT); - } - - Object temp; - temp=props.get(Config.CADI_PROTOCOLS); - if (props.get(Config.HTTPS_PROTOCOLS)==null && temp!=null) { - props.put(Config.HTTPS_PROTOCOLS, temp); - } + SecurityInfo.setHTTPProtocols(this); - if (temp!=null) { - if ("1.7".equals(System.getProperty("java.specification.version")) - && (temp==null || (temp instanceof String && ((String)temp).contains("TLSv1.2")))) { - System.setProperty(Config.HTTPS_CIPHER_SUITES, Config.HTTPS_CIPHER_SUITES_DEFAULT); - } - } } - + + private void load(String cadi_prop_files) { if (cadi_prop_files==null) { return; } String prevKeyFile = props.getProperty(Config.CADI_KEYFILE); - int prev = 0, end = cadi_prop_files.length(); - int idx; - String filename; - while (prev es : fileProps.entrySet()) { + if(props.get(es.getKey())==null) { + String key = es.getKey().toString(); + String value = es.getValue().toString(); + props.put(key, value); + if(key.contains("pass")) { + value = "XXXXXXX"; + } + printf(Level.DEBUG," %s=%s",key,value); + } + } // Recursively Load - String chainProp = props.getProperty(Config.CADI_PROP_FILES); + String chainProp = fileProps.getProperty(Config.CADI_PROP_FILES); if (chainProp!=null) { if (recursionProtection==null) { recursionProtection = new ArrayList<>(); @@ -201,7 +204,6 @@ public class PropAccess implements Access { } else { printf(Level.WARN,"Warning: recursive CADI Property %s does not exist",file.getAbsolutePath()); } - prev = idx+1; } // Trim @@ -241,8 +243,6 @@ public class PropAccess implements Access { printf(Level.ERROR,"%s=%s is an Invalid Log Level",Config.CADI_LOGLEVEL,loglevel); } } - - specialConversions(); } @Override @@ -262,53 +262,72 @@ public class PropAccess implements Access { return buildMsg(name,iso8601,level,elements); } - public static StringBuilder buildMsg(final String name, final SimpleDateFormat sdf, Level level, Object[] elements) { - StringBuilder sb = new StringBuilder(sdf.format(new Date())); - sb.append(' '); - sb.append(level.name()); - sb.append(" ["); - sb.append(name); - + public static StringBuilder buildMsg(final String name, final DateFormat sdf, Level level, Object[] elements) { + final StringBuilder sb; int end = elements.length; - if (end<=0) { - sb.append("] "); - } else { - int idx = 0; - if (elements[idx] instanceof Integer) { - sb.append('-'); - sb.append(elements[idx]); - ++idx; - } - sb.append("] "); - String s; - boolean first = true; - for (Object o : elements) { - if (o!=null) { - s=o.toString(); - if (first) { - first = false; - } else { - int l = s.length(); - if (l>0) { - switch(s.charAt(l-1)) { - case ' ': - break; - default: - sb.append(' '); - } - } - } - sb.append(s); - } + if(sdf==null) { + sb = new StringBuilder(); + write(true,sb,elements); + } else { + sb = new StringBuilder( + sdf.format(new Date()) + ); + sb.append(' '); + sb.append(level.name()); + sb.append(" ["); + sb.append(name); + if (end<=0) { + sb.append("] "); + } else { + int idx = 0; + if(elements[idx]!=null && + elements[idx] instanceof Integer) { + sb.append('-'); + sb.append(elements[idx]); + ++idx; + } + sb.append("] "); + write(true,sb,elements); + } + } + return sb; + } + + private static boolean write(boolean first, StringBuilder sb, Object[] elements) { + String s; + for (Object o : elements) { + if (o!=null) { + if(o.getClass().isArray()) { + first = write(first,sb,(Object[])o); + } else { + s=o.toString(); + if (first) { + first = false; + } else { + int l = s.length(); + if (l>0) { + switch(s.charAt(l-1)) { + case ' ': + break; + default: + sb.append(' '); + } + } + } + sb.append(s); + } } } - return sb; + return first; } @Override public void log(Exception e, Object... elements) { - log(Level.ERROR,e.getMessage(),elements); - e.printStackTrace(System.err); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pw.println(); + e.printStackTrace(pw); + log(Level.ERROR,elements,sw.toString()); } @Override @@ -392,10 +411,17 @@ public class PropAccess implements Access { ps.println(buildMsg(level,elements)); ps.flush(); } - } public void set(LogIt logit) { logIt = logit; } + + public void setStreamLogIt(PrintStream ps) { + logIt = new StreamLogIt(ps); + } + + public String toString() { + return props.toString(); + } }