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.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
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(HttpServletRequest req, HttpServletResponse resp) {
47 AuthzTrans trans = env.newTrans();
53 protected TimeTaken start(AuthzTrans trans) {
54 return trans.start("Trans " + //(context==null?"n/a":context.toString()) +
55 " IP: " + trans.ip() +
56 " Port: " + trans.port()
61 protected void authenticated(AuthzTrans trans, TaggedPrincipal p) {
66 protected void tallyHo(AuthzTrans trans) {
67 // Transaction is done, now post
68 StringBuilder sb = new StringBuilder("AuditTrail\n");
69 // We'll grab sub-metrics for Remote Calls and JSON
70 // IMPORTANT!!! if you add more entries here, change "BUCKETSIZE"!!!
71 Metric m = trans.auditTrail(1, sb, Env.REMOTE,Env.JSON);
72 // Add current Metrics to total metrics
73 serviceMetric.total+= m.total;
74 for (int i=0;i<serviceMetric.buckets.length;++i) {
75 serviceMetric.buckets[i]+=m.buckets[i];
78 sb.append(" Total: ");
80 sb.append(" Remote: ");
81 sb.append(m.buckets[0]);
83 sb.append(m.buckets[1]);