2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.env;
24 import javax.servlet.ServletRequest;
25 import javax.servlet.http.HttpServletRequest;
27 import org.onap.aaf.auth.rserv.TransOnlyFilter;
28 import org.onap.aaf.cadi.principal.TaggedPrincipal;
29 import org.onap.aaf.misc.env.Env;
30 import org.onap.aaf.misc.env.TimeTaken;
31 import org.onap.aaf.misc.env.Trans.Metric;
33 public class AuthzTransOnlyFilter extends TransOnlyFilter<AuthzTrans> {
35 public Metric serviceMetric;
37 public static final int BUCKETSIZE = 2;
39 public AuthzTransOnlyFilter(AuthzEnv env) {
41 serviceMetric = new Metric();
42 serviceMetric.buckets = new float[BUCKETSIZE];
46 protected AuthzTrans newTrans() {
47 return env.newTrans();
51 protected TimeTaken start(AuthzTrans trans, ServletRequest request) {
52 trans.set((HttpServletRequest)request);
53 return trans.start("Trans " + //(context==null?"n/a":context.toString()) +
54 " IP: " + trans.ip() +
55 " Port: " + trans.port()
60 protected void authenticated(AuthzTrans trans, TaggedPrincipal p) {
65 protected void tallyHo(AuthzTrans trans) {
66 // Transaction is done, now post
67 StringBuilder sb = new StringBuilder("AuditTrail\n");
68 // We'll grab sub-metrics for Remote Calls and JSON
69 // IMPORTANT!!! if you add more entries here, change "BUCKETSIZE"!!!
70 Metric m = trans.auditTrail(1, sb, Env.REMOTE,Env.JSON);
71 // Add current Metrics to total metrics
72 serviceMetric.total+= m.total;
73 for (int i=0;i<serviceMetric.buckets.length;++i) {
74 serviceMetric.buckets[i]+=m.buckets[i];
77 sb.append(" Total: ");
79 sb.append(" Remote: ");
80 sb.append(m.buckets[0]);
82 sb.append(m.buckets[1]);