Merge "Sonar fix: BatchDataView.java"
[aaf/authz.git] / auth / auth-core / src / main / java / org / onap / aaf / auth / env / AuthzTransFilter.java
index 06fd310..bd9f887 100644 (file)
@@ -23,8 +23,8 @@ package org.onap.aaf.auth.env;
 
 import java.security.Principal;
 
-import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.onap.aaf.auth.rserv.TransFilter;
 import org.onap.aaf.cadi.CadiException;
@@ -54,25 +54,24 @@ public class AuthzTransFilter extends TransFilter<AuthzTrans> {
         this.env = env;
         serviceMetric = new Metric();
         serviceMetric.buckets = new float[BUCKETSIZE];
-        if(transIDslot==null) {
+        if (transIDslot==null) {
             transIDslot = env.slot(TRANS_ID_SLOT);
         }
-        if(specialLogSlot==null) {
+        if (specialLogSlot==null) {
             specialLogSlot = env.slot(SPECIAL_LOG_SLOT);
         }
     }
     
     @Override
-    protected AuthzTrans newTrans(HttpServletRequest req) {
+    protected AuthzTrans newTrans(HttpServletRequest req, HttpServletResponse resp) {
         AuthzTrans at = env.newTrans();
         at.setLur(getLur());
-        at.set(req);
+        at.set(req,resp);
         return at;
     }
 
     @Override
-    protected TimeTaken start(AuthzTrans trans, ServletRequest request) {
-        trans.set((HttpServletRequest)request);
+    protected TimeTaken start(AuthzTrans trans) {
         return trans.start("Trans " + //(context==null?"n/a":context.toString()) +
         " IP: " + trans.ip() +
         " Port: " + trans.port()
@@ -85,11 +84,11 @@ public class AuthzTransFilter extends TransFilter<AuthzTrans> {
     }
 
     @Override
-    protected void tallyHo(AuthzTrans trans) {
+    protected void tallyHo(AuthzTrans trans, String target) {
         Boolean b = trans.get(specialLogSlot, false);
-        LogTarget lt = b?trans.warn():trans.info();
+        LogTarget lt = b?trans.warn():trans.debug();
         
-        if(lt.isLoggable()) {
+        if (lt.isLoggable()) {
             // Transaction is done, now post full Audit Trail
             StringBuilder sb = new StringBuilder("AuditTrail\n");
             // We'll grabAct sub-metrics for Remote Calls and JSON
@@ -98,12 +97,12 @@ public class AuthzTransFilter extends TransFilter<AuthzTrans> {
 
             // Add current Metrics to total metrics
             serviceMetric.total+= m.total;
-            for(int i=0;i<serviceMetric.buckets.length;++i) {
+            for (int i=0;i<serviceMetric.buckets.length;++i) {
                 serviceMetric.buckets[i]+=m.buckets[i];
             }
             
             Long tsi;
-            if((tsi=trans.get(transIDslot, null))!=null) {
+            if ((tsi=trans.get(transIDslot, null))!=null) {
                 sb.append("  TraceID=");
                 sb.append(Long.toHexString(tsi));
                 sb.append('\n');
@@ -123,24 +122,27 @@ public class AuthzTransFilter extends TransFilter<AuthzTrans> {
             Metric m = trans.auditTrail(lt,1, content, Env.REMOTE,Env.JSON);
             // Add current Metrics to total metrics
             serviceMetric.total+= m.total;
-            for(int i=0;i<serviceMetric.buckets.length;++i) {
+            for (int i=0;i<serviceMetric.buckets.length;++i) {
                 serviceMetric.buckets[i]+=m.buckets[i];
             }
             
             StringBuilder sb = new StringBuilder();
             sb.append("user=");
             Principal p = trans.getUserPrincipal();
-            if(p==null) {
-                sb.append("n/a");
+            if (p==null) {
+                lt=trans.warn();
+                sb.append(target);
+                sb.append("[None]");
             } else {
+                lt=trans.info();
                 sb.append(p.getName());
-                if(p instanceof TrustPrincipal) {
+                if (p instanceof TrustPrincipal) {
                     sb.append('(');
                     sb.append(((TrustPrincipal)p).personalName()); // UserChain
                     sb.append(')');
                 } else { 
                     sb.append('[');
-                    if(p instanceof TaggedPrincipal) {
+                    if (p instanceof TaggedPrincipal) {
                         sb.append(((TaggedPrincipal)p).tag());
                     } else {
                         sb.append(p.getClass().getSimpleName());
@@ -148,27 +150,34 @@ public class AuthzTransFilter extends TransFilter<AuthzTrans> {
                     sb.append(']');
                 }
             }
+            String tag = trans.getTag();
+            if(tag!=null) {
+                sb.append(",tag=");
+                sb.append(tag);
+            }
             sb.append(",ip=");
             sb.append(trans.ip());
             sb.append(",port=");
             sb.append(trans.port());
 //            Current code won't ever get here... Always does a Full Audit Trail
 //            Long tsi;
-//            if((tsi=trans.get(transIDslot, null))!=null) {
+//            if ((tsi=trans.get(transIDslot, null))!=null) {
 //                sb.append(",TraceID=");
 //                sb.append(Long.toHexString(tsi));
 //            }
             sb.append(",ms=");
             sb.append(m.total);
+            sb.append(",status=");
+            sb.append(trans.hresp().getStatus());
             sb.append(",meth=");
             sb.append(trans.meth());
             sb.append(",path=");
             sb.append(trans.path());
 
-            if(content.length()>0) {
+            if (content.length()>0) {
                 sb.append(",msg=\"");
                 int start = content.lastIndexOf(",msg=\"");
-                if(start>=0) {
+                if (start>=0) {
                     sb.append(content,start+6,content.length()-1);
                 } else {
                     sb.append(content);
@@ -176,7 +185,7 @@ public class AuthzTransFilter extends TransFilter<AuthzTrans> {
                 sb.append('"');
             }
             
-            trans.warn().log(sb);
+            lt.log(sb);
         }
     }