Add a MassMail Batch Program
[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
33 import org.onap.aaf.cadi.util.Holder;
34
35 /**
36  * Add various Filters by CADI Property not in the official Chain
37  *
38  * @author Instrumental(Jonathan)
39  *
40  */
41 public class SideChain {
42     private List<Filter> sideChain;
43
44     public SideChain() {
45         sideChain = new ArrayList<Filter>();
46     }
47
48     public void add(Filter f) {
49         sideChain.add(f);
50     }
51
52     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException {
53         final Holder<Boolean> hbool = new Holder<Boolean>(Boolean.TRUE);
54         FilterChain truth = new FilterChain() {
55             @Override
56             public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
57                hbool.set(Boolean.TRUE);
58             }
59             public String toString() {
60                 return hbool.get().toString();
61             }
62         };
63         for(Filter f : sideChain) {
64             hbool.set(Boolean.FALSE);
65             f.doFilter(request, response, truth);
66             if(!hbool.get()) {
67                 return;
68             }
69         }
70         if(hbool.get()) {
71             chain.doFilter(request, response);
72         }
73     }
74 }