summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorInstrumental <jcgmisc@stl.gathman.org>2018-04-03 21:30:32 -0500
committerInstrumental <jcgmisc@stl.gathman.org>2018-04-03 21:30:38 -0500
commitabf7c0e407c97250c07d408c314c5aa1c757263e (patch)
treebf37f2b5872c4f8f756a3b2a08abf907ec1c6ce1
parenta88f56fb9096afa3d48ff9d71190cec49d2b6673 (diff)
Create method of Logging to O/S from Container
Issue-ID: AAF-211 Change-Id: Ib5c369c24082823f6f8cfde7609b966f57085665 Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java7
-rw-r--r--auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java17
-rw-r--r--auth/auth-core/pom.xml5
-rw-r--r--auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java87
-rw-r--r--auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java12
-rw-r--r--auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java100
-rw-r--r--auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java18
-rw-r--r--auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java17
-rw-r--r--auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java20
-rw-r--r--auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java17
-rw-r--r--auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java17
-rw-r--r--auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java17
-rw-r--r--auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java1
-rw-r--r--auth/auth-service/.gitignore1
-rw-r--r--auth/auth-service/pom.xml6
-rw-r--r--auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java28
-rw-r--r--cadi/core/src/main/java/org/onap/aaf/cadi/Access.java2
-rw-r--r--cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java34
-rw-r--r--cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java3
-rw-r--r--cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java2
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java2
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java27
-rw-r--r--misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java50
23 files changed, 352 insertions, 138 deletions
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
index 64c09711..d4b582a3 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
@@ -422,12 +422,7 @@ public abstract class Batch {
// Flow all Env Logs to Log4j, with ENV
LogFileNamer lfn;
- if ((batchEnv = env.getProperty(CASS_ENV)) == null) {
- lfn = new LogFileNamer(logDir()).noPID();
- } else {
- lfn = new LogFileNamer(logDir()).noPID();
- }
-
+ lfn = new LogFileNamer(logDir(),"").noPID();
lfn.setAppender("authz-batch");
lfn.setAppender("aspr|ASPR");
lfn.setAppender("sync");
diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java
index c1bc8202..aee48870 100644
--- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java
+++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java
@@ -22,6 +22,7 @@
package org.onap.aaf.auth.cm;
+import java.io.File;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.Map.Entry;
@@ -49,6 +50,7 @@ import org.onap.aaf.auth.env.AuthzTransFilter;
import org.onap.aaf.auth.rserv.HttpMethods;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
@@ -226,10 +228,21 @@ public class AAF_CM extends AbsService<AuthzEnv, AuthzTrans> {
}
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "cm");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
AAF_CM service = new AAF_CM(new AuthzEnv(propAccess));
-// env.setLog4JNames("log4j.properties","authz","cm","audit","init","trace");
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.start();
} catch (Exception e) {
diff --git a/auth/auth-core/pom.xml b/auth/auth-core/pom.xml
index d0d2fb6e..a7f60aea 100644
--- a/auth/auth-core/pom.xml
+++ b/auth/auth-core/pom.xml
@@ -119,7 +119,10 @@
<scope>compile</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java
index 300e4087..a396cd98 100644
--- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java
@@ -29,14 +29,11 @@ import java.util.Properties;
import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.PropAccess.LogIt;
import org.onap.aaf.cadi.Symm;
import org.onap.aaf.cadi.config.Config;
-import org.onap.aaf.misc.env.APIException;
import org.onap.aaf.misc.env.Decryptor;
import org.onap.aaf.misc.env.Encryptor;
-import org.onap.aaf.misc.env.impl.Log4JLogTarget;
-import org.onap.aaf.misc.env.log4j.LogFileNamer;
+import org.onap.aaf.misc.env.LogTarget;
import org.onap.aaf.misc.rosetta.env.RosettaEnv;
@@ -79,39 +76,46 @@ public class AuthzEnv extends RosettaEnv implements Access {
access = pa;
times = new long[20];
idx = 0;
+ fatal = new AccessLogTarget(access, Level.ERROR);
+ error = fatal;
+ audit = new AccessLogTarget(access, Level.AUDIT);
+ init = new AccessLogTarget(access, Level.INIT);
+ warn = new AccessLogTarget(access, Level.WARN);
+ info = new AccessLogTarget(access, Level.INFO);
+ debug = new AccessLogTarget(access, Level.DEBUG);
+ trace = new AccessLogTarget(access, Level.TRACE);
}
- private class Log4JLogit implements LogIt {
+ private class AccessLogTarget implements LogTarget {
+ private final Level level;
+ private final Access access;
+
+ public AccessLogTarget(final Access access, final Level level) {
+ this.level = level;
+ this.access = access;
+ }
@Override
- public void push(Level level, Object... elements) {
- switch(level) {
- case AUDIT:
- audit.log(elements);
- break;
- case DEBUG:
- debug.log(elements);
- break;
- case ERROR:
- error.log(elements);
- break;
- case INFO:
- info.log(elements);
- break;
- case INIT:
- init.log(elements);
- break;
- case NONE:
- break;
- case WARN:
- warn.log(elements);
- break;
- }
-
+ public void log(Object... msgs) {
+ access.log(level, msgs);
+ }
+
+ @Override
+ public void log(Throwable e, Object... msgs) {
+ access.log(Level.ERROR, msgs);
+ }
+
+ @Override
+ public boolean isLoggable() {
+ return access.willLog(level);
+ }
+
+ @Override
+ public void printf(String fmt, Object... vars) {
+ access.printf(level, fmt, vars);
}
}
-
@Override
public AuthzTransImpl newTrans() {
synchronized(this) {
@@ -192,29 +196,6 @@ public class AuthzEnv extends RosettaEnv implements Access {
public void setLogLevel(Level level) {
access.setLogLevel(level);
}
-
- public void setLog4JNames(String path, String root, String _service, String _audit, String _init, String _trace) throws APIException {
- LogFileNamer lfn = new LogFileNamer(root);
- if(_service==null) {
- throw new APIException("AuthzEnv.setLog4JNames \"_service\" required (as default). Others can be null");
- }
- String service=_service=lfn.setAppender(_service); // when name is split, i.e. authz|service, the Appender is "authz", and "service"
- String audit=_audit==null?service:lfn.setAppender(_audit); // is part of the log-file name
- String init=_init==null?service:lfn.setAppender(_init);
- String trace=_trace==null?service:lfn.setAppender(_trace);
- //TODO Validate path on Classpath
- lfn.configure(path);
- super.fatal = new Log4JLogTarget(service,org.apache.log4j.Level.FATAL);
- super.error = new Log4JLogTarget(service,org.apache.log4j.Level.ERROR);
- super.warn = new Log4JLogTarget(service,org.apache.log4j.Level.WARN);
- super.audit = new Log4JLogTarget(audit,org.apache.log4j.Level.WARN);
- super.init = new Log4JLogTarget(init,org.apache.log4j.Level.WARN);
- super.info = new Log4JLogTarget(service,org.apache.log4j.Level.INFO);
- super.debug = new Log4JLogTarget(service,org.apache.log4j.Level.DEBUG);
- super.trace = new Log4JLogTarget(trace,org.apache.log4j.Level.TRACE);
-
- access.set(new Log4JLogit());
- }
private static final byte[] ENC="enc:".getBytes();
public String decrypt(String encrypted, final boolean anytext) throws IOException {
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 e1c01718..12b19d29 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
@@ -46,6 +46,7 @@ import org.onap.aaf.misc.env.Trans;
import org.onap.aaf.misc.env.impl.BasicEnv;
public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> extends RServlet<TRANS> {
+ protected static final String AAF_LOG4J_PREFIX = "aaf_log4j_prefix";
public final Access access;
public final ENV env;
private AAFConHttp aafCon;
@@ -153,4 +154,15 @@ public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> exte
public<RET> RET clientAsUser(TaggedPrincipal p,Retryable<RET> retryable) throws APIException, LocatorException, CadiException {
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;
+ String tagEQ = tag + '=';
+ for(String arg : args) {
+ if(arg.startsWith(tagEQ)) {
+ value = arg.substring(tagEQ.length());
+ }
+ }
+ return value;
+ }
}
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
new file mode 100644
index 00000000..0b91c9fc
--- /dev/null
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java
@@ -0,0 +1,100 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.server;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+
+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.misc.env.APIException;
+import org.onap.aaf.misc.env.log4j.LogFileNamer;
+
+public class Log4JLogIt implements LogIt {
+ // 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");
+
+ private final String service;
+ private final String audit;
+ private final String init;
+ private final String trace;
+
+ private final Logger lservice;
+ private final Logger laudit;
+ private final Logger linit;
+ private final Logger ltrace;
+
+
+ public Log4JLogIt(final String log_dir, final String log_level, final String propsFile, final String root) throws APIException {
+ 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"
+ audit=lfn.setAppender("audit"); // is part of the log-file name
+ init=lfn.setAppender("init");
+ trace=lfn.setAppender("trace");
+
+ lservice = Logger.getLogger(service);
+ laudit = Logger.getLogger(audit);
+ linit = Logger.getLogger(init);
+ ltrace = Logger.getLogger(trace);
+
+ lfn.configure(propsFile, log_level);
+ } catch (IOException e) {
+ throw new APIException(e);
+ }
+ }
+
+ @Override
+ public void push(Level level, Object... elements) {
+ switch(level) {
+ case AUDIT:
+ laudit.warn(PropAccess.buildMsg(audit, iso8601, level, elements));
+ break;
+ case INIT:
+ linit.warn(PropAccess.buildMsg(init, iso8601, level, elements));
+ break;
+ case ERROR:
+ lservice.error(PropAccess.buildMsg(service, iso8601, level, elements));
+ break;
+ case WARN:
+ lservice.warn(PropAccess.buildMsg(service, iso8601, level, elements));
+ break;
+ case INFO:
+ lservice.info(PropAccess.buildMsg(service, iso8601, level, elements));
+ break;
+ case DEBUG:
+ lservice.debug(PropAccess.buildMsg(service, iso8601, level, elements));
+ break;
+ case TRACE:
+ ltrace.trace(PropAccess.buildMsg(service, iso8601, level, elements));
+ break;
+ case NONE:
+ break;
+ default:
+ lservice.info(PropAccess.buildMsg(service, iso8601, level, elements));
+ break;
+
+ }
+
+ }
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
index 4d088c5a..6413b099 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
@@ -21,22 +21,20 @@
******************************************************************************/
package org.onap.aaf.auth.env.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
-import org.onap.aaf.cadi.Access;
-import static org.mockito.Mockito.when;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.Access.Level;
-import org.onap.aaf.cadi.config.Config;
-import org.onap.aaf.misc.env.APIException;
import org.powermock.modules.junit4.PowerMockRunner;
import junit.framework.Assert;
@@ -85,12 +83,6 @@ public class JU_AuthzEnv {
Assert.assertNotNull(authzEnv.getProperties("test"));
}
- @Test(expected = APIException.class)
- public void checkSetLog4JNames() throws APIException {//TODO: Find better way to test instead of just seeing if strings pass
- authzEnv.setLog4JNames("path", "root","service","audit","init","trace");
- authzEnv.setLog4JNames("path", "root",null,"audit","init","trace");
- }
-
@Test
public void checkPropertyGetters(){
authzEnv.setProperty("key","value");
diff --git a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java
index 50791393..719daaae 100644
--- a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java
+++ b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java
@@ -23,6 +23,7 @@ package org.onap.aaf.auth.fs;
import static org.onap.aaf.auth.rserv.HttpMethods.GET;
+import java.io.File;
import java.io.IOException;
import javax.servlet.Filter;
@@ -36,6 +37,7 @@ import org.onap.aaf.auth.rserv.CachingFileAccess;
import org.onap.aaf.auth.rserv.HttpCode;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.cadi.Access.Level;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
@@ -102,10 +104,21 @@ public class AAF_FS extends AbsService<AuthzEnv, AuthzTrans> {
}
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "fs");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
AAF_FS service = new AAF_FS(new AuthzEnv(propAccess));
-// env.setLog4JNames("log4j.properties","authz","fs","audit","init",null);
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.insecure().start();
} catch (Exception e) {
diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java
index be93d63c..676866bb 100644
--- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java
+++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java
@@ -25,6 +25,8 @@ import static org.onap.aaf.auth.rserv.HttpMethods.GET;
import static org.onap.aaf.auth.rserv.HttpMethods.POST;
import static org.onap.aaf.auth.rserv.HttpMethods.PUT;
+import java.io.File;
+
import javax.servlet.Filter;
import org.onap.aaf.auth.cmd.Cmd;
@@ -68,6 +70,7 @@ import org.onap.aaf.auth.gui.pages.WebCommand;
import org.onap.aaf.auth.rserv.CachingFileAccess;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
@@ -254,10 +257,21 @@ public class AAF_GUI extends AbsService<AuthzEnv, AuthzTrans> implements State<E
}
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
- AAF_GUI service = new AAF_GUI(new AuthzEnv(propAccess));
-// env.setLog4JNames("log4j.properties","authz","gui","audit","init","trace ");
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "authz");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
+ AAF_GUI service = new AAF_GUI(new AuthzEnv(propAccess));
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.start();
} catch (Exception e) {
diff --git a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java
index 97448bdd..b20bf168 100644
--- a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java
+++ b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java
@@ -22,6 +22,7 @@
package org.onap.aaf.auth.hello;
+import java.io.File;
import java.util.Map;
import javax.servlet.Filter;
@@ -34,6 +35,7 @@ import org.onap.aaf.auth.rserv.HttpCode;
import org.onap.aaf.auth.rserv.HttpMethods;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
@@ -116,10 +118,21 @@ public class AAF_Hello extends AbsService<AuthzEnv,AuthzTrans> {
}
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "hello");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess));
-// env.setLog4JNames("log4j.properties","authz","hello","audit","init","trace");
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.start();
} catch (Exception e) {
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java
index 92fc88c7..31f67726 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java
@@ -22,6 +22,7 @@
package org.onap.aaf.auth.locate;
+import java.io.File;
import java.net.URI;
import java.util.Map;
@@ -46,6 +47,7 @@ import org.onap.aaf.auth.locate.mapper.Mapper.API;
import org.onap.aaf.auth.rserv.HttpMethods;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.LocatorException;
@@ -230,10 +232,21 @@ public class AAF_Locate extends AbsService<AuthzEnv, AuthzTrans> {
}
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "locate");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
AAF_Locate service = new AAF_Locate(new AuthzEnv(propAccess));
-// service.env().setLog4JNames("log4j.properties","authz","gw","audit","init","trace");
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.start();
} catch (Exception e) {
diff --git a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java
index 1dac22fc..846d1a53 100644
--- a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java
+++ b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java
@@ -22,6 +22,7 @@
package org.onap.aaf.auth.oauth;
+import java.io.File;
import java.util.Map;
import javax.servlet.Filter;
@@ -45,6 +46,7 @@ import org.onap.aaf.auth.rserv.HttpCode;
import org.onap.aaf.auth.rserv.HttpMethods;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
@@ -183,10 +185,21 @@ public class AAF_OAuth extends AbsService<AuthzEnv,AuthzTrans> {
}
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "oauth");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
AAF_OAuth service = new AAF_OAuth(new AuthzEnv(propAccess));
-// env.setLog4JNames("log4j.properties","authz","oauth","audit","init","trace");
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.start();
} catch (Exception e) {
diff --git a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
index e602e863..16d72686 100644
--- a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
+++ b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
@@ -101,6 +101,7 @@ public class DirectOAuthTAF implements HttpTaf {
}
if("application/x-www-form-urlencoded".equals(req.getContentType())) {
+ @SuppressWarnings("unchecked")
Map<String, String[]> map = req.getParameterMap();
String client_id=null,client_secret=null,username=null,password=null;
for(Map.Entry<String, String[]> es : map.entrySet()) {
diff --git a/auth/auth-service/.gitignore b/auth/auth-service/.gitignore
index 6028f0a5..f3bad092 100644
--- a/auth/auth-service/.gitignore
+++ b/auth/auth-service/.gitignore
@@ -2,3 +2,4 @@
/.settings/
/target/
/.project
+/logs/
diff --git a/auth/auth-service/pom.xml b/auth/auth-service/pom.xml
index 7f806f84..4acec253 100644
--- a/auth/auth-service/pom.xml
+++ b/auth/auth-service/pom.xml
@@ -28,7 +28,6 @@
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<!-- SONAR -->
- <sonar.skip>true</sonar.skip>
<jacoco.version>0.7.7.201606060606</jacoco.version>
<sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
@@ -90,11 +89,6 @@
<artifactId>jetty-servlet</artifactId>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
-
</dependencies>
<build>
diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java
index ad9ccc4a..0040912f 100644
--- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java
+++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java
@@ -21,6 +21,8 @@
package org.onap.aaf.auth.service;
+import java.io.File;
+
import javax.servlet.Filter;
import org.onap.aaf.auth.cache.Cache;
@@ -38,6 +40,7 @@ import org.onap.aaf.auth.org.OrganizationFactory;
import org.onap.aaf.auth.rserv.HttpMethods;
import org.onap.aaf.auth.server.AbsService;
import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
import org.onap.aaf.auth.service.api.API_Api;
import org.onap.aaf.auth.service.api.API_Approval;
import org.onap.aaf.auth.service.api.API_Creds;
@@ -59,6 +62,7 @@ import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator;
import org.onap.aaf.cadi.config.Config;
import org.onap.aaf.cadi.register.Registrant;
import org.onap.aaf.cadi.taf.basic.BasicHttpTaf;
+import org.onap.aaf.cadi.util.FQI;
import org.onap.aaf.misc.env.APIException;
import org.onap.aaf.misc.env.Data;
import org.onap.aaf.misc.env.Env;
@@ -68,12 +72,8 @@ import com.datastax.driver.core.Cluster;
public class AAF_Service extends AbsService<AuthzEnv,AuthzTrans> {
private static final String ORGANIZATION = "Organization.";
- private static final String DOMAIN = "aaf.att.com";
-// TODO Add Service Metrics
-// private Metric serviceMetric;
public final Question question;
-// private final SessionFilter sessionFilter;
private AuthzFacade_2_0 facade;
private AuthzFacade_2_0 facade_XML;
private DirectAAFUserPass directAAFUserPass;
@@ -160,13 +160,14 @@ public class AAF_Service extends AbsService<AuthzEnv,AuthzTrans> {
@Override
public Filter[] filters() throws CadiException {
+ final String domain = FQI.reverseDomain(access.getProperty("aaf_root_ns","org.osaaf.aaf"));
try {
return new Filter[] {new AuthzTransFilter(env, null /* no connection to AAF... it is AAF */,
new AAFTrustChecker((Env)env),
new DirectAAFLur(env,question), // Note, this will be assigned by AuthzTransFilter to TrustChecker
//new DirectOAuthTAF(env,question,OAFacadeFactory.directV1_0(oauthService)),
new BasicHttpTaf(env, directAAFUserPass,
- DOMAIN,Long.parseLong(env.getProperty(Config.AAF_CLEAN_INTERVAL, Config.AAF_CLEAN_INTERVAL_DEF)),
+ domain,Long.parseLong(env.getProperty(Config.AAF_CLEAN_INTERVAL, Config.AAF_CLEAN_INTERVAL_DEF)),
false)
)};
} catch (NumberFormatException e) {
@@ -214,10 +215,21 @@ public class AAF_Service extends AbsService<AuthzEnv,AuthzTrans> {
* Start up AAF_Service as Jetty Service
*/
public static void main(final String[] args) {
- PropAccess propAccess = new PropAccess(args);
try {
- AAF_Service service = new AAF_Service(new AuthzEnv(propAccess));
-// service.env().setLog4JNames("log4j.properties","authz","authz|service","audit","init","trace");
+ String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+ String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+ String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+ File logs = new File(log_dir);
+ if(!logs.isDirectory()) {
+ logs.delete();
+ }
+ if(!logs.exists()) {
+ logs.mkdirs();
+ }
+ Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "authz");
+ PropAccess propAccess = new PropAccess(logIt,args);
+
+ AbsService<AuthzEnv, AuthzTrans> service = new AAF_Service(new AuthzEnv(propAccess));
JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
jss.start();
} catch (Exception e) {
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java
index 7a9e63be..83127238 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java
@@ -37,7 +37,7 @@ import java.util.Properties;
public interface Access {
// levels to use
public enum Level {
- DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),NONE(0XFFFF);
+ DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),TRACE(0x10000),NONE(0XFFFF);
private final int bit;
Level(int ord) {
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 bd1ad72d..c827477f 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
@@ -31,12 +31,11 @@ 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");
@@ -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";
@@ -248,9 +252,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(" [");
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
index 65cb81a5..82645c31 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
@@ -452,7 +452,8 @@ public class Symm {
switch(read) {
case -1:
case '=':
- case '\n':
+ case '\n':
+ case '\r':
return -1;
}
for(int i=0;i<range.length;++i) {
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java
index 0c011541..0de6f4ef 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java
@@ -73,6 +73,7 @@ public class Config {
public static final String HOSTNAME = "hostname";
public static final String CADI_PROP_FILES = "cadi_prop_files"; // Additional Properties files (separate with ;)
public static final String CADI_LOGLEVEL = "cadi_loglevel";
+ public static final String CADI_LOGDIR = "cadi_logdir";
public static final String CADI_LOGNAME = "cadi_logname";
public static final String CADI_KEYFILE = "cadi_keyfile";
public static final String CADI_KEYSTORE = "cadi_keystore";
@@ -82,6 +83,7 @@ public class Config {
public static final String CADI_LATITUDE = "cadi_latitude";
public static final String CADI_LONGITUDE = "cadi_longitude";
+
public static final String CADI_KEY_PASSWORD = "cadi_key_password";
public static final String CADI_TRUSTSTORE = "cadi_truststore";
public static final String CADI_TRUSTSTORE_PASSWORD = "cadi_truststore_password";
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java
index d62144ce..98903567 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java
@@ -44,7 +44,7 @@ public class JU_Access {
assertThat(Level.DEBUG.delFromMask(0x1), is(0x0));
assertThat(Level.DEBUG.toggle(0x2), is(0x3));
assertThat(Level.DEBUG.toggle(0x1), is(0x0));
- assertThat(Level.DEBUG.maskOf(), is(57617));
+ assertThat(Level.DEBUG.maskOf(), is(123153));
assertThat(Level.NONE.maskOf(), is(0));
}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
index 533fe91f..b2820db2 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
@@ -32,6 +32,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -42,6 +43,7 @@ import java.util.Properties;
import org.onap.aaf.cadi.CmdLine;
import org.onap.aaf.cadi.PropAccess;
import org.onap.aaf.cadi.Symm;
+import org.onap.aaf.cadi.util.Chmod;
public class JU_CmdLine {
@@ -67,11 +69,30 @@ public class JU_CmdLine {
p.setProperty("force_exit", "false");
CmdLine.access = new PropAccess(p);
-
- password = "password";
+ File test = new File("test");
+ if(test.exists()) {
+ if(!test.isDirectory()) {
+ test.delete();
+ test.mkdirs();
+ }
+ } else {
+ test.mkdirs();
+ }
+
+ File keyF= new File(test,"keyfile");
+ if(!keyF.exists()) {
+ FileOutputStream fos = new FileOutputStream(keyF);
+ try {
+ fos.write(Symm.keygen());
+ fos.flush();
+ } finally {
+ fos.close();
+ }
+ }
keyfile = "test/keyfile";
+ password = "password";
- FileInputStream fis = new FileInputStream(keyfile);
+ FileInputStream fis = new FileInputStream(keyF);
try {
symm = Symm.obtain(fis);
} finally {
diff --git a/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java b/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java
index 7174912f..ff7b43f0 100644
--- a/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java
+++ b/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java
@@ -22,56 +22,68 @@
package org.onap.aaf.misc.env.log4j;
import java.io.File;
+import java.io.IOException;
import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
public class LogFileNamer {
- public final String root;
+ private final String root;
+ private final String ending;
+ private final String dir;
- public LogFileNamer(String root) {
+ public LogFileNamer(final String dir, final String root) {
+ this.dir = dir;
if(root==null || "".equals(root) || root.endsWith("/")) {
this.root = root;
} else {
this.root = root + "-";
}
+ ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
}
public LogFileNamer noPID() {
return this;
}
+
+ private static final String FILE_FORMAT_STR = "%s/%s%s%s_%d.log";
/**
* Accepts a String.
* If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming
* (This is to allow for shortened Logger names, and more verbose file names)
+ * ONAP: jna code has license issues. Just do Date + Unique Number
*
* @param appender
*
* returns the String Appender
+ * @throws IOException
*/
- public String setAppender(String appender) {
- int pipe = appender.indexOf('|');
- if(pipe>=0) {
- String rv;
- System.setProperty(
- "LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)),
- root + appender.substring(pipe+1) + ".log");
- return rv;
- } else {
- System.setProperty(
- "LOG4J_FILENAME_"+appender,
- root + appender + ".log");
- return appender;
- }
-
+ public String setAppender(String appender) throws IOException {
+ String filename;
+ int i=0;
+ File f;
+ while((f=new File(filename=String.format(FILE_FORMAT_STR, dir,root, appender, ending,i))).exists()) {
+ ++i;
+ };
+ f.createNewFile();
+ System.setProperty(
+ "LOG4J_FILENAME_"+(appender),
+ filename);
+ return appender;
}
- public void configure(String props) {
+ public void configure(final String props, final String log_level) throws IOException {
String fname;
if(new File(fname="etc/"+props).exists()) {
org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000L);
} else {
URL rsrc = ClassLoader.getSystemResource(props);
- if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" );
+ if(rsrc==null) {
+ String msg = "Neither File: " + fname + " or resource on Classpath " + props + " exist" ;
+ throw new IOException(msg);
+ }
org.apache.log4j.PropertyConfigurator.configure(rsrc);
}
+
}
}