Remove Tabs, per Jococo
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / filter / SideChain.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  */
20
21 package org.onap.aaf.cadi.filter;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import javax.servlet.Filter;
28 import javax.servlet.FilterChain;
29 import javax.servlet.ServletException;
30 import javax.servlet.ServletRequest;
31 import javax.servlet.ServletResponse;
32 import javax.xml.ws.Holder;
33
34 /**
35  * Add various Filters by CADI Property not in the official Chain
36  * 
37  * @author Instrumental(Jonathan)
38  *
39  */
40 public class SideChain {
41     private List<Filter> sideChain;
42     
43     public SideChain() {
44         sideChain = new ArrayList<Filter>();
45     }
46     
47     public void add(Filter f) {
48         sideChain.add(f);
49     }
50     
51     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException {
52         final Holder<Boolean> hbool = new Holder<Boolean>(Boolean.TRUE);
53         FilterChain truth = new FilterChain() {
54             @Override
55             public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
56                hbool.value=Boolean.TRUE;
57             }
58             public String toString() {
59                 return hbool.value.toString();
60             }
61         };
62         for(Filter f : sideChain) {
63             hbool.value=Boolean.FALSE;
64             f.doFilter(request, response, truth);
65             if(!hbool.value) {
66                 return;
67             }
68         }
69         if(hbool.value) {
70             chain.doFilter(request, response);
71         }
72     }
73 }