X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aaf%2Fauthz.git;a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2FPropAccess.java;h=c4719f86727efca7df3fa49bfe248d06a8d475ba;hp=92756d8cd7ddad4ab3bdafe72f7c23e3cf5e7283;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hpb=bdce7667a6e272e2fa32e298d957a0d9090c5bc9 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 92756d8c..c4719f86 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 @@ -3,15 +3,15 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. - * + * * Modifications Copyright (C) 2018 IBM. * =========================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -59,7 +59,7 @@ public class PropAccess implements Access { logIt = new StreamLogIt(System.out); init(null); } - + /** * This Constructor soly exists to instantiate Servlet Context Based Logging that will call "init" later. * @param sc @@ -68,29 +68,29 @@ public class PropAccess implements Access { logIt = new StreamLogIt(System.out); props = new Properties(); } - + public PropAccess(String ... args) { this(System.out,args); } - + public PropAccess(PrintStream ps, String[] args) { logIt = new StreamLogIt(ps==null?System.out:ps); init(logIt,args); } - + public PropAccess(LogIt logit, String[] args) { init(logit, args); } - + public PropAccess(Properties p) { this(System.out,p); } - + public PropAccess(PrintStream ps, Properties p) { logIt = new StreamLogIt(ps==null?System.out:ps); init(p); } - + protected void init(final LogIt logIt, final String[] args) { this.logIt = logIt; Properties nprops=new Properties(); @@ -102,7 +102,7 @@ public class PropAccess implements Access { } init(nprops); } - + public static SimpleDateFormat newISO8601() { return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); } @@ -110,7 +110,7 @@ public class PropAccess implements Access { protected synchronized void init(Properties p) { // Make sure these two are set before any changes in Logging name = "cadi"; - + props = new Properties(); // First, load related System Properties for (Entry es : System.getProperties().entrySet()) { @@ -119,24 +119,24 @@ public class PropAccess implements Access { if (key.startsWith(start)) { props.put(key, es.getValue()); } - } + } } // Second, overlay or fill in with Passed in Props if (p!=null) { props.putAll(p); } - + // Preset LogLevel - String sLevel = props.getProperty(Config.CADI_LOGLEVEL); + String sLevel = props.getProperty(Config.CADI_LOGLEVEL); // 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); + sLevel = props.getProperty(Config.CADI_LOGLEVEL); if (sLevel==null) { level=DEFAULT.maskOf(); } else { - level=Level.valueOf(sLevel).maskOf(); + level=Level.valueOf(sLevel).maskOf(); } } // Setup local Symmetrical key encryption @@ -149,21 +149,21 @@ public class PropAccess implements Access { System.exit(1); } } - + name = props.getProperty(Config.CADI_LOGNAME, name); - + SecurityInfo.setHTTPProtocols(this); - + } - - + + private void load(String cadi_prop_files) { if (cadi_prop_files==null) { return; } String prevKeyFile = props.getProperty(Config.CADI_KEYFILE); - + for(String filename : Split.splitTrim(File.pathSeparatorChar, cadi_prop_files)) { Properties fileProps = new Properties(); File file = new File(filename); @@ -208,8 +208,8 @@ public class PropAccess implements Access { printf(Level.WARN,"Warning: recursive CADI Property %s does not exist",file.getAbsolutePath()); } } - - // Trim + + // Trim for (Entry es : props.entrySet()) { Object value = es.getValue(); if (value instanceof String) { @@ -237,7 +237,7 @@ public class PropAccess implements Access { prevKeyFile=newKeyFile; } - + String loglevel = props.getProperty(Config.CADI_LOGLEVEL); if (loglevel!=null) { try { @@ -247,7 +247,7 @@ public class PropAccess implements Access { } } } - + @Override public void load(InputStream is) throws IOException { props.load(is); @@ -264,7 +264,7 @@ public class PropAccess implements Access { public StringBuilder buildMsg(Level level, Object[] elements) { return buildMsg(name,iso8601,level,elements); } - + /* * Need to pass in DateFormat per thread, because not marked as thread safe */ @@ -286,7 +286,7 @@ public class PropAccess implements Access { sb.append("] "); } else { int idx = 0; - if(elements[idx]!=null && + if(elements[idx]!=null && elements[idx] instanceof Integer) { sb.append('-'); sb.append(elements[idx]); @@ -298,7 +298,7 @@ public class PropAccess implements Access { } return sb; } - + private static boolean write(boolean first, StringBuilder sb, Object[] elements) { String s; for (Object o : elements) { @@ -374,7 +374,7 @@ public class PropAccess implements Access { ? symm.depass(encrypted) : encrypted; } - + public String encrypt(String unencrypted) throws IOException { return Symm.ENC+symm.enpass(unencrypted); } @@ -385,7 +385,7 @@ public class PropAccess implements Access { public String getProperty(String tag) { return props.getProperty(tag); } - + public Properties getProperties() { return props; @@ -410,10 +410,10 @@ public class PropAccess implements Access { public interface LogIt { public void push(Level level, Object ... elements) ; } - + private class StreamLogIt implements LogIt { private PrintStream ps; - + public StreamLogIt(PrintStream ps) { this.ps = ps; }