summaryrefslogtreecommitdiffstats
path: root/auth/auth-core/src/main
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 /auth/auth-core/src/main
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>
Diffstat (limited to 'auth/auth-core/src/main')
-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
3 files changed, 146 insertions, 53 deletions
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;
+
+ }
+
+ }
+}