AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-gui / src / main / java / org / onap / aaf / auth / gui / XFrameFilter.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.auth.gui;
22
23 import java.io.IOException;
24
25 import javax.servlet.Filter;
26 import javax.servlet.FilterChain;
27 import javax.servlet.FilterConfig;
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletRequest;
30 import javax.servlet.ServletResponse;
31 import javax.servlet.http.HttpServletResponse;
32
33 public class XFrameFilter implements Filter {
34         enum TYPE {none,self};
35         // Note: Content-Security Params need to be worked out for GUI before activating.
36         private final String xframe;//,csp;
37         
38         public XFrameFilter(TYPE type) {
39                 switch(type) {
40                 case self:
41                         xframe="SAMEORIGIN";
42 //                      csp="default-src 'self'";
43                         break;
44                 case none:
45                 default:
46                         xframe="DENY";
47 //                      csp="default-src 'none'";
48                         break;
49                 
50                 }
51         }
52         
53         @Override
54         public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc) throws IOException, ServletException {
55                 if(resp instanceof HttpServletResponse) {
56                         @SuppressWarnings("unused")
57                         HttpServletResponse hresp = (HttpServletResponse)resp;
58                         ((HttpServletResponse)resp).addHeader("X-Frame-Options", xframe);
59 //                      ((HttpServletResponse)resp).addHeader("Content-Security-Policy",csp);
60                 }
61                 fc.doFilter(req, resp);
62         }
63
64         @Override
65         public void init(FilterConfig fc) throws ServletException {
66         }
67
68         @Override
69         public void destroy() {
70         }
71
72
73 }