Adjust sparky parent pom
[aai/sparky-be.git] / sparkybe-onap-application / src / main / java / org / onap / aai / sparky / portal / PortalBean.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.sparky.portal;
22
23 import javax.servlet.Filter;
24
25 import org.onap.aai.sparky.security.filter.LoginFilter;
26 import org.onap.portalsdk.core.onboarding.crossapi.CadiAuthFilter;
27 import org.onap.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy;
28 import org.springframework.beans.factory.annotation.Value;
29 import org.springframework.boot.web.servlet.FilterRegistrationBean;
30 import org.springframework.boot.web.servlet.ServletRegistrationBean;
31 import org.springframework.context.annotation.Bean;
32 import org.springframework.context.annotation.Profile;
33 import org.springframework.stereotype.Component;
34
35 @Component
36 @Profile("portal")
37 public class PortalBean {
38
39   private Filter loginFilter = new LoginFilter();
40   private Filter cadiAuthFilter = new CadiAuthFilter();
41   
42   @Value("${portal.cadiFileLocation}")
43   private String cadiPropsLocation; 
44
45   /**
46    * bind LoginFilter
47    */
48   @Bean
49   public FilterRegistrationBean loginFilterRegistrationBean() {
50     FilterRegistrationBean registration = new FilterRegistrationBean();
51     registration.setFilter(loginFilter);
52     registration.addUrlPatterns("/*");
53     registration.setOrder(1);
54
55     return registration;
56   }
57   
58   /**
59    * bind CadiAuthFilter
60    */
61   @Bean
62   public FilterRegistrationBean cadiFilterRegistrationBean() {
63     FilterRegistrationBean registration = new FilterRegistrationBean();
64
65     registration.setFilter(cadiAuthFilter);
66     registration.addUrlPatterns("/*");
67     registration.setOrder(0);
68     registration.addInitParameter("cadi_prop_files",cadiPropsLocation);
69     registration.addInitParameter("include_url_endpoints","/api/v3/*");
70     registration.addInitParameter("exclude_url_endpoints","/api/v2/*");
71
72     return registration;
73   }
74
75   @Bean
76   public ServletRegistrationBean portalApiProxy() {
77
78     final ServletRegistrationBean servlet =
79         new ServletRegistrationBean(new PortalRestAPIProxy(), "/api/v3/*");
80     servlet.setName("PortalRestApiProxy");
81     return servlet;
82   }
83
84 }