1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\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
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\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
17 package org.oran.otf.api.config;
\r
19 import javax.servlet.Filter;
\r
20 import javax.servlet.FilterConfig;
\r
21 import javax.servlet.ServletException;
\r
22 import org.onap.aaf.cadi.Access;
\r
23 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
\r
24 import org.springframework.boot.web.servlet.FilterRegistrationBean;
\r
25 import org.springframework.context.annotation.Bean;
\r
26 import org.springframework.context.annotation.Conditional;
\r
27 import org.springframework.context.annotation.Configuration;
\r
28 import org.springframework.context.annotation.PropertySource;
\r
30 @PropertySource("classpath:application.properties")
\r
32 @ConditionalOnProperty(prefix = "aaf",name ="enabled",havingValue = "true")
\r
33 public class OTFApiEnforcementFilterConfiguration {
\r
35 private Access access;
\r
36 private FilterConfig fc;
\r
38 @Bean(name = "otfApiEnforcementFilterRegistrationBean")
\r
39 @ConditionalOnProperty(prefix = "aaf",name ="enabled",havingValue = "true")
\r
40 public FilterRegistrationBean<Filter> otfApiEnforcementFilterRegistration()
\r
41 throws ServletException {
\r
42 FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
\r
43 initFilterParameters(registration);
\r
44 registration.addUrlPatterns("/otf/api/testInstance/*", "/otf/api/testExecution/*", "/otf/api/testStrategy/*", "/otf/api/virtualTestHead/*");
\r
45 registration.setFilter(otfApiEnforcementFilter());
\r
46 registration.setName("otfApiEnforcementFilter");
\r
47 registration.setOrder(1);
\r
48 return registration;
\r
51 @Bean(name = "otfApiEnforcementFilter")
\r
52 @ConditionalOnProperty(prefix = "aaf",name ="enabled",havingValue = "true")
\r
53 public Filter otfApiEnforcementFilter() throws ServletException {
\r
54 return new OTFApiEnforcementFilter(access, System.getenv("AAF_PERM_TYPE"));
\r
57 private void initFilterParameters(FilterRegistrationBean<Filter> registration) {
\r
58 registration.addInitParameter("aaf_perm_type", System.getenv("AAF_PERM_TYPE"));
\r