652bfc2213730ccde0439d118a1ba20d6c5b5326
[dmaap/messagerouter/messageservice.git] / src / main / java / com / att / nsa / dmaap / util / DMaaPAuthFilter.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 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  *        http://www.apache.org/licenses/LICENSE-2.0
11 *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *  
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package com.att.nsa.dmaap.util;
23
24 import java.io.IOException;
25
26 import javax.servlet.FilterChain;
27 import javax.servlet.ServletException;
28 import javax.servlet.ServletRequest;
29 import javax.servlet.ServletResponse;
30 import javax.servlet.http.HttpServletRequest;
31
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.springframework.stereotype.Component;
35
36 import org.onap.aaf.cadi.filter.CadiFilter;
37 //import ajsc.external.plugins.cadi.AjscCadiFilter;
38 import javax.servlet.FilterConfig;
39
40 /**
41          * This is a Servlet Filter class
42          * overriding the AjscCadiFilter
43          */
44 @Component      
45 public class DMaaPAuthFilter extends CadiFilter {
46         
47                 //private Logger log = Logger.getLogger(DMaaPAuthFilter.class.toString());
48
49                 private static final EELFLogger log = EELFManager.getInstance().getLogger(DMaaPAuthFilter.class);
50                                 
51                 public DMaaPAuthFilter() throws Exception {
52                         super();
53                 }
54                 
55         /*      public void init(FilterConfig filterConfig) throws ServletException {
56               
57                         super.init(filterConfig);
58               System.out.println("---------------------------- in init method");
59                 }*/
60                 
61                 /**
62                  * This method will disable Cadi Authentication 
63                  * if cambria headers are present in the request
64                  * else continue with Cadi Authentication
65                  */
66                 @Override
67                 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
68                                 ServletException {
69                 log.info("inside servlet filter Cambria Auth Headers checking before doing other Authentication");
70                         HttpServletRequest request = (HttpServletRequest) req;
71                                 boolean forceAAF = Boolean.valueOf(System.getProperty("forceAAF"));
72                                 //if (forceAAF || null != request.getHeader("Authorization") ){
73                                         if (forceAAF || null != request.getHeader("Authorization") || 
74                                                         (null != request.getHeader("AppName") &&  request.getHeader("AppName").equalsIgnoreCase("invenio") &&
75                                                          null != request.getHeader("cookie"))){
76                                                 super.doFilter(req, res, chain);
77                                                 
78                                 } else { 
79                                         System.setProperty("CadiAuthN", "authentication-scheme-2");
80                                                 chain.doFilter(req, res);
81                                         
82                                         
83                                 } 
84
85                 }
86
87         }
88