added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / cadi / configuration / OTFApiEnforcementFilterConfiguration.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.cadi.configuration;\r
18 \r
19 import org.oran.otf.cadi.filter.OTFApiEnforcementFilter;\r
20 import javax.servlet.Filter;\r
21 import javax.servlet.FilterConfig;\r
22 import javax.servlet.ServletException;\r
23 import org.onap.aaf.cadi.Access;\r
24 import org.springframework.beans.factory.annotation.Value;\r
25 import org.springframework.boot.web.servlet.FilterRegistrationBean;\r
26 import org.springframework.context.annotation.Bean;\r
27 import org.springframework.context.annotation.Conditional;\r
28 import org.springframework.context.annotation.Configuration;\r
29 import org.springframework.context.annotation.PropertySource;\r
30 \r
31 @PropertySource("classpath:application.yaml")\r
32 @Configuration\r
33 @Conditional(value = FilterCondition.class)\r
34 public class OTFApiEnforcementFilterConfiguration {\r
35 \r
36   @Value("${otf.cadi.aaf-perm-type}")\r
37   private String AAF_PERM_TYPE;\r
38 \r
39   private Access access;\r
40   private FilterConfig fc;\r
41 \r
42   @Bean(name = "otfApiEnforcementFilterRegistrationBean")\r
43 //  @ConditionalOnProperty(prefix ="otf.cadi", name ="enabled", havingValue = "true" ,matchIfMissing = true)\r
44   @Conditional(value = FilterCondition.class)\r
45   public FilterRegistrationBean<Filter> otfApiEnforcementFilterRegistration()\r
46       throws ServletException {\r
47     FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();\r
48     initFilterParameters(registration);\r
49 \r
50     registration.addUrlPatterns("/otf/tcu/*", "/rest/*");\r
51     registration.setFilter(otfApiEnforcementFilter());\r
52     registration.setName("otfApiEnforcementFilter");\r
53     registration.setOrder(1);\r
54     return registration;\r
55   }\r
56 \r
57   @Bean(name = "otfApiEnforcementFilter")\r
58   @Conditional(value = FilterCondition.class)\r
59 //  @ConditionalOnProperty(prefix ="otf.cadi", name ="enabled", havingValue = "true", matchIfMissing = true)\r
60   Filter otfApiEnforcementFilter() throws ServletException {\r
61     return new OTFApiEnforcementFilter(access, AAF_PERM_TYPE);\r
62   }\r
63 \r
64   private void initFilterParameters(FilterRegistrationBean<Filter> registration) {\r
65     registration.addInitParameter("aaf_perm_type", AAF_PERM_TYPE);\r
66   }\r
67 }\r