2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music;
26 import javax.servlet.Filter;
27 import javax.servlet.FilterChain;
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletRequest;
30 import javax.servlet.ServletResponse;
32 import org.onap.aaf.cadi.PropAccess;
33 import org.onap.music.authentication.CadiAuthFilter;
34 import org.onap.music.main.MusicUtil;
35 import org.onap.music.main.PropertiesLoader;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
38 import org.springframework.boot.autoconfigure.SpringBootApplication;
39 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
40 import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
41 import org.springframework.boot.builder.SpringApplicationBuilder;
42 import org.springframework.boot.web.servlet.FilterRegistrationBean;
43 //import org.springframework.boot.web.support.SpringBootServletInitializer;
44 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
45 import org.springframework.context.ApplicationContext;
46 import org.springframework.context.annotation.Bean;
47 import org.springframework.context.annotation.ComponentScan;
48 import org.springframework.context.annotation.DependsOn;
49 import org.springframework.scheduling.annotation.EnableScheduling;
50 import org.springframework.web.context.request.RequestContextListener;
53 @SpringBootApplication(scanBasePackages = { "org.onap.music.rest"})
54 @EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class})
55 @ComponentScan(value = {"org.onap.music"})
57 public class MusicApplication extends SpringBootServletInitializer {
60 PropertiesLoader propertyLoader;
63 public static void main(String[] args) {
64 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG","false");
65 System.setProperty("AFT_DME2_CLIENT_KEYSTORE","/opt/app/music/etc/truststore2018.jks");
66 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD","changeit");
67 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS","TLSv1.1,TLSv1.2");
68 new MusicApplication().configure(new SpringApplicationBuilder(MusicApplication.class)).run(args);
72 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
74 return application.sources(MusicApplication.class);
78 @Bean("loadProperties")
79 public void loadProperties() {
80 propertyLoader.loadProperties();
84 private ApplicationContext appContext;
87 @DependsOn("loadProperties")
88 public PropAccess propAccess() {
89 if(MusicUtil.getIsCadi())
90 return new PropAccess(new String[] { "cadi_prop_files=/opt/app/music/etc/cadi.properties" });
95 @Bean(name = "cadiFilter")
96 @DependsOn("loadProperties")
97 public Filter cadiFilter() throws ServletException {
98 propertyLoader.loadProperties();
99 if(MusicUtil.getIsCadi()) {
100 PropAccess propAccess = propAccess();
101 CadiAuthFilter cadiFilter = new CadiAuthFilter(propAccess);
104 return (ServletRequest request, ServletResponse response, FilterChain chain) -> {
105 //do nothing for now.
111 @DependsOn("loadProperties")
112 public FilterRegistrationBean<Filter> cadiFilterRegistration() throws ServletException {
113 FilterRegistrationBean<Filter> frb = new FilterRegistrationBean<>();
114 frb.setFilter(cadiFilter());
115 // The Following Patterns are used to control what APIs will be secure
116 // TODO: Make this a configurable item. Build this from an array?
117 if(MusicUtil.getIsCadi()) {
126 frb.addUrlPatterns("/v0/test");
128 frb.setName("cadiFilter");
134 @ConditionalOnMissingBean(RequestContextListener.class)
135 public RequestContextListener requestContextListener() {
136 return new RequestContextListener();