From 924b18d7469204ceaae60d7345712ea09f75a674 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Thu, 5 Apr 2018 20:17:18 -0500 Subject: Add Certs, Docker Build Issue-ID: AAF-211 Change-Id: Idc7630578155586a6e53d7af80dd16e4e0ac41ca Signed-off-by: Instrumental --- .../java/org/onap/aaf/auth/server/AbsService.java | 21 +++++++++--- .../java/org/onap/aaf/auth/server/Log4JLogIt.java | 37 ++++++++++++++++++++-- 2 files changed, 51 insertions(+), 7 deletions(-) (limited to 'auth/auth-core/src') diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java index 12b19d29..d8c73117 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java @@ -22,6 +22,7 @@ package org.onap.aaf.auth.server; import java.security.NoSuchAlgorithmException; +import java.util.Properties; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; @@ -46,7 +47,6 @@ import org.onap.aaf.misc.env.Trans; import org.onap.aaf.misc.env.impl.BasicEnv; public abstract class AbsService extends RServlet { - protected static final String AAF_LOG4J_PREFIX = "aaf_log4j_prefix"; public final Access access; public final ENV env; private AAFConHttp aafCon; @@ -155,14 +155,25 @@ public abstract class AbsService exte return aafCon.hman().best(new HTransferSS(p,app_name, aafCon.securityInfo()), retryable); } - protected static final String getArg(final String tag, final String args[], final String def) { - String value = def; + protected static final String loadFromArgOrSystem(final Properties props, final String tag, final String args[], final String def) { String tagEQ = tag + '='; + String value; for(String arg : args) { if(arg.startsWith(tagEQ)) { - value = arg.substring(tagEQ.length()); + props.put(tag, value=arg.substring(tagEQ.length())); + return value; } } - return value; + // check System.properties + value = System.getProperty(tag); + if(value!=null) { + props.put(tag, value); + return value; + } + + if(def!=null) { + props.put(tag,def); + } + return def; } } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java index 0b91c9fc..e295c867 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java @@ -20,6 +20,7 @@ */ package org.onap.aaf.auth.server; +import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; @@ -27,10 +28,13 @@ import org.apache.log4j.Logger; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.PropAccess.LogIt; +import org.onap.aaf.cadi.config.Config; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.log4j.LogFileNamer; public class Log4JLogIt implements LogIt { + protected static final String AAF_LOG4J_PREFIX = "aaf_log4j_prefix"; + // 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"); @@ -45,7 +49,19 @@ public class Log4JLogIt implements LogIt { private final Logger ltrace; - public Log4JLogIt(final String log_dir, final String log_level, final String propsFile, final String root) throws APIException { + public Log4JLogIt(final String[] args, final String root) throws APIException { + String propsFile = getArgOrVM(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props"; + String log_dir = getArgOrVM(Config.CADI_LOGDIR,args,"/opt/app/osaaf/logs"); + String etc_dir = getArgOrVM(Config.CADI_ETCDIR,args,"/opt/app/osaaf/etc"); + String log_level = getArgOrVM(Config.CADI_LOGLEVEL,args,"INFO"); + File logs = new File(log_dir); + if(!logs.isDirectory()) { + logs.delete(); + } + if(!logs.exists()) { + logs.mkdirs(); + } + LogFileNamer lfn = new LogFileNamer(log_dir,root); try { service=lfn.setAppender("service"); // when name is split, i.e. authz|service, the Appender is "authz", and "service" @@ -58,12 +74,29 @@ public class Log4JLogIt implements LogIt { linit = Logger.getLogger(init); ltrace = Logger.getLogger(trace); - lfn.configure(propsFile, log_level); + lfn.configure(etc_dir,propsFile, log_level); } catch (IOException e) { throw new APIException(e); } } + private static final String getArgOrVM(final String tag, final String args[], final String def) { + String tagEQ = tag + '='; + String value; + for(String arg : args) { + if(arg.startsWith(tagEQ)) { + return arg.substring(tagEQ.length()); + } + } + // check System.properties + value = System.getProperty(tag); + if(value!=null) { + return value; + } + + return def; + } + @Override public void push(Level level, Object... elements) { switch(level) { -- cgit 1.2.3-korg