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.rserv;
24 import java.io.IOException;
26 import javax.servlet.Filter;
27 import javax.servlet.FilterChain;
28 import javax.servlet.FilterConfig;
29 import javax.servlet.ServletException;
30 import javax.servlet.ServletRequest;
31 import javax.servlet.ServletResponse;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
35 import org.onap.aaf.cadi.principal.TaggedPrincipal;
36 import org.onap.aaf.misc.env.TimeTaken;
37 import org.onap.aaf.misc.env.TransStore;
40 * Create a new Transaction Object for each and every incoming Transaction
42 * Attach to Request. User "FilterHolder" mechanism to retain single instance.
44 * TransFilter includes CADIFilter as part of the package, so that it can
45 * set User Data, etc, as necessary.
50 public abstract class TransOnlyFilter<TRANS extends TransStore> implements Filter {
52 public void init(FilterConfig filterConfig) throws ServletException {
57 protected abstract TRANS newTrans(HttpServletRequest req, HttpServletResponse resp);
58 protected abstract TimeTaken start(TRANS trans);
59 protected abstract void authenticated(TRANS trans, TaggedPrincipal p);
60 protected abstract void tallyHo(TRANS trans);
63 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
64 TRANS trans = newTrans((HttpServletRequest)request,(HttpServletResponse)response);
65 TimeTaken overall = start(trans);
67 request.setAttribute(TransFilter.TRANS_TAG, trans);
68 chain.doFilter(request, response);
76 public void destroy() {