quoted props
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / PropAccess.java
index bd1ad72..3d15b09 100644 (file)
@@ -31,17 +31,16 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.Properties;
 
 import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.config.SecurityInfo;
 
-import java.util.Properties;
-
 public class PropAccess implements Access {
        // Sonar says cannot be static... it's ok.  not too many PropAccesses created.
        private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
 
-       public static Level DEFAULT = Level.AUDIT;
+       public static final Level DEFAULT = Level.AUDIT;
        
        private Symm symm;
        private int level;
@@ -70,18 +69,11 @@ public class PropAccess implements Access {
        
        public PropAccess(PrintStream ps, String[] args) {
                logIt = new StreamLogIt(ps==null?System.out:ps);
-               Properties nprops=new Properties();
-               int eq;
-               for(String arg : args) {
-                       if((eq=arg.indexOf('='))>0) {
-                               nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1));
-                       }
-               }
-               init(nprops);
+               init(logIt,args);
        }
        
        public PropAccess(LogIt logit, String[] args) {
-               logIt = logit;
+               init(logit, args);
        }
        
        public PropAccess(Properties p) {
@@ -93,6 +85,18 @@ public class PropAccess implements Access {
                init(p);
        }
        
+       protected void init(final LogIt logIt, final String[] args) {
+               this.logIt = logIt;
+               Properties nprops=new Properties();
+               int eq;
+               for(String arg : args) {
+                       if((eq=arg.indexOf('='))>0) {
+                               nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1));
+                       }
+               }
+               init(nprops);
+       }
+       
        protected void init(Properties p) {
                // Make sure these two are set before any changes in Logging
                name = "cadi";
@@ -180,7 +184,7 @@ public class PropAccess implements Access {
                                                String chainProp = props.getProperty(Config.CADI_PROP_FILES);
                                                if(chainProp!=null) {
                                                        if(recursionProtection==null) {
-                                                               recursionProtection = new ArrayList<String>();
+                                                               recursionProtection = new ArrayList<>();
                                                                recursionProtection.add(cadi_prop_files);
                                                        }
                                                        if(!recursionProtection.contains(chainProp)) {
@@ -205,6 +209,11 @@ public class PropAccess implements Access {
                        Object value = es.getValue();
                        if(value instanceof String) {
                                String trim = ((String)value).trim();
+                               // Remove Beginning/End Quotes, which might be there if mixed with Bash Props
+                               int s = 0, e=trim.length()-1;
+                               if(s<e && trim.charAt(s)=='"' && trim.charAt(e)=='"') {
+                                       trim=trim.substring(s+1,e);
+                               }
                                if(trim!=value) { // Yes, I want OBJECT equals
                                        props.setProperty((String)es.getKey(), trim);
                                }
@@ -248,9 +257,13 @@ public class PropAccess implements Access {
                        logIt.push(level,elements);
                }
        }
-       
+
        protected StringBuilder buildMsg(Level level, Object[] elements) {
-               StringBuilder sb = new StringBuilder(iso8601.format(new Date()));
+               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(" [");