push addional code
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / onboarding-rest-war / src / main / java / org / openecomp / server / filters / ActionAuthorizationFilter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 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  * 
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.openecomp.server.filters;
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.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33
34 public class ActionAuthorizationFilter implements Filter {
35
36   private boolean runningOnLocal = true;
37
38   @Override
39   public void destroy() {
40   }
41
42   @Override
43   public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
44       throws IOException, ServletException {
45
46     if (runningOnLocal) {
47       HttpServletRequest httpRequest = (HttpServletRequest) arg0;
48       if (httpRequest.isUserInRole(httpRequest.getMethod().toUpperCase())) {
49         arg2.doFilter(arg0, arg1);
50       } else {
51         setResponseStatus((HttpServletResponse) arg1, HttpServletResponse.SC_FORBIDDEN);
52       }
53     } else {
54       //call super doFilter of cadi authorization filter with relavant info as and when available
55     }
56
57   }
58
59   private void setResponseStatus(HttpServletResponse response, int status) {
60     response.setStatus(status);
61   }
62
63   @Override
64   public void init(FilterConfig arg0) throws ServletException {
65     /*runningOnLocal = System.getProperty("file.separator").equals("\\");
66     if (!runningOnLocal){
67     // call to super init of cadi filter as we are not running on windows
68     }*/
69   }
70
71 }