diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-05-29 04:58:50 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-05-29 07:34:28 -0500 |
commit | ff1417ff60baee231a28272f9a16ef2c9c8ea0a2 (patch) | |
tree | d9ca6c5f9661a3ffd6263d1380812e2430d9b230 /auth/auth-core/src/main | |
parent | a47bd51641efcb84e19d68a6383f0947df826636 (diff) |
Post Init Service Starter
minor fixes
Remove JU generated garbage files
Issue-ID: AAF-835
Change-Id: I476291f1f1140f0640ed49452f8a5dabb28d9c30
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-core/src/main')
9 files changed, 54 insertions, 36 deletions
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java index 2bae29b5..0256c1bf 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTrans.java @@ -43,6 +43,8 @@ public interface AuthzTrans extends TransStore { public abstract AuthzTrans set(HttpServletRequest req); + public abstract HttpServletRequest hreq(); + public abstract String user(); public abstract void setUser(TaggedPrincipal p); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java index aa6b038b..ce947be9 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzTransImpl.java @@ -34,16 +34,16 @@ import org.onap.aaf.misc.env.LogTarget; import org.onap.aaf.misc.env.impl.BasicTrans; public class AuthzTransImpl extends BasicTrans implements AuthzTrans { + private static final String N_A = "n/a"; + private static final String BLANK = ""; + private HttpServletRequest hreq; private TaggedPrincipal user; - private String ip,agent,meth,path; - private int port; private Lur lur; private Organization org; private int mask; private Date now; public AuthzTransImpl(AuthzEnv env) { super(env); - ip="n/a"; org=null; mask=0; } @@ -53,12 +53,8 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public AuthzTrans set(HttpServletRequest req) { + hreq = req; user = (TaggedPrincipal)req.getUserPrincipal(); - ip = req.getRemoteAddr(); - port = req.getRemotePort(); - agent = req.getHeader("User-Agent"); - meth = req.getMethod(); - path = req.getPathInfo(); for (REQD_TYPE rt : REQD_TYPE.values()) { requested(rt,req); @@ -72,6 +68,10 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { org=null; return this; } + @Override + public HttpServletRequest hreq() { + return hreq; + } @Override public void setUser(TaggedPrincipal p) { @@ -83,7 +83,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String user() { - return user==null?"n/a":user.getName(); + return user==null?N_A:user.getName(); } /** @@ -99,7 +99,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String ip() { - return ip; + return hreq==null?N_A:hreq.getRemoteAddr(); } /** @@ -107,7 +107,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public int port() { - return port; + return hreq==null?0:hreq.getRemotePort(); } @@ -116,7 +116,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String meth() { - return meth; + return hreq==null?"":hreq.getMethod(); } /* (non-Javadoc) @@ -124,7 +124,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String path() { - return path; + return hreq==null?"":hreq.getPathInfo(); } /** @@ -132,7 +132,7 @@ public class AuthzTransImpl extends BasicTrans implements AuthzTrans { */ @Override public String agent() { - return agent; + return hreq==null?BLANK:hreq.getHeader("User-Agent"); } @Override diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java index 942a0e54..94a6aad5 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/NullTrans.java @@ -135,6 +135,11 @@ public class NullTrans implements AuthzTrans { } @Override + public HttpServletRequest hreq() { + return null; + } + + @Override public String user() { return null; } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java index fa17f040..a269f24b 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java @@ -154,10 +154,10 @@ public class CachingFileAccess<TRANS extends Trans> extends HttpCode<TRANS, Void @Override public void handle(TRANS trans, HttpServletRequest req, HttpServletResponse resp) throws IOException { String key = pathParam(req, ":key"); - String cmd = pathParam(req,":cmd"); - if (key.equals(clear_command)) { + int slash = key.indexOf('/'); + if(key.length()>2 && slash>=0 && key.substring(0,slash).equals(clear_command)) { resp.setHeader("Content-Type",typeMap.get("txt")); - if ("clear".equals(cmd)) { + if ("clear".equals(key.substring(slash+1))) { content.clear(); resp.setStatus(200/*HttpStatus.OK_200*/); } else { @@ -165,7 +165,7 @@ public class CachingFileAccess<TRANS extends Trans> extends HttpCode<TRANS, Void } return; } - Content c = load(logT , web_path,cmd!=null && cmd.length()>0?key+'/'+cmd:key, null, checkInterval); + Content c = load(logT , web_path,key, null, checkInterval); if (c.attachmentOnly) { resp.setHeader("Content-disposition", "attachment"); } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java index c1bfd6ad..acca80ba 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/RServlet.java @@ -32,6 +32,9 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; import org.onap.aaf.misc.env.Trans; @@ -122,6 +125,15 @@ public abstract class RServlet<TRANS extends Trans> implements Servlet { return "RServlet for Jetty"; } + /** + * Allow Service to instantiate certain actions after service starts up + * @throws LocatorException + * @throws CadiException + * @throws APIException + */ + public void postStartup(String hostname, int port) throws APIException { + } + @Override public void destroy() { } diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java index 85b35ac7..d0fc1a3f 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/TransFilter.java @@ -138,8 +138,9 @@ public abstract class TransFilter<TRANS extends TransStore> implements Filter { // Would need Cached Counter objects that are cleaned up on // use trans.checkpoint(resp.desc(),Env.ALWAYS); - if (resp.isFailedAttempt()) + if (resp.isFailedAttempt()) { trans.audit().log(resp.desc()); + } } } catch (Exception e) { trans.error().log(e); diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java index b3e2883d..0e8cb78d 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsServiceStarter.java @@ -67,8 +67,9 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr } } - public abstract void _start(RServlet<TRANS> rserv) throws Exception; - public abstract void _propertyAdjustment(); + + protected abstract void _start(RServlet<TRANS> rserv) throws Exception; + protected abstract void _propertyAdjustment(); public ENV env() { return service.env; @@ -103,10 +104,8 @@ public abstract class AbsServiceStarter<ENV extends RosettaEnv, TRANS extends Tr } catch (IOException e) { } } - } - @SafeVarargs public final synchronized void register(final Registrant<ENV> ... registrants) { if (do_register) { diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java index 182956cf..bcc071a2 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/JettyServiceStarter.java @@ -216,7 +216,8 @@ public class JettyServiceStarter<ENV extends RosettaEnv, TRANS extends Trans> ex access().printf(Level.INIT,"'aaf_no_register' is set. %s will not be registered with Locator", service.app_name); } access().printf(Level.INIT, "Starting Jetty Service for %s, version %s, on %s://%s:%d", service.app_name,service.app_version,protocol,hostname,port); - //server.join(); + + rserv.postStartup(hostname, port); } catch (Exception e) { access().log(e,"Error registering " + service.app_name); String doExit = access().getProperty("cadi_exitOnFailure", "true"); 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 fd0691b6..894f571d 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 @@ -22,7 +22,6 @@ package org.onap.aaf.auth.server; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; import org.apache.log4j.Logger; import org.onap.aaf.cadi.Access.Level; @@ -31,12 +30,11 @@ 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; +import org.onap.aaf.misc.env.util.Chrono; 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"); + // Log4j does it's own date. Can't apparently turn it off. private final String service; private final String audit; @@ -104,30 +102,30 @@ public class Log4JLogIt implements LogIt { public void push(Level level, Object... elements) { switch(level) { case AUDIT: - laudit.warn(PropAccess.buildMsg(audit, iso8601, level, elements)); + laudit.warn(PropAccess.buildMsg(audit, Chrono.utcFmt, level, elements)); break; case INIT: - linit.warn(PropAccess.buildMsg(init, iso8601, level, elements)); + linit.warn(PropAccess.buildMsg(init, Chrono.utcFmt, level, elements)); break; case ERROR: - lservice.error(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.error(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case WARN: - lservice.warn(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.warn(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case INFO: - lservice.info(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.info(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case DEBUG: - lservice.debug(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.debug(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case TRACE: - ltrace.trace(PropAccess.buildMsg(service, iso8601, level, elements)); + ltrace.trace(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; case NONE: break; default: - lservice.info(PropAccess.buildMsg(service, iso8601, level, elements)); + lservice.info(PropAccess.buildMsg(service, Chrono.utcFmt, level, elements)); break; } |