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.main.MusicUtil;
34 import org.onap.music.main.PropertiesLoader;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
37 import org.springframework.boot.autoconfigure.SpringBootApplication;
38 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
39 import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
40 import org.springframework.boot.builder.SpringApplicationBuilder;
41 import org.springframework.boot.web.servlet.FilterRegistrationBean;
42 //import org.springframework.boot.web.support.SpringBootServletInitializer;
43 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
44 import org.springframework.context.ApplicationContext;
45 import org.springframework.context.annotation.Bean;
46 import org.springframework.context.annotation.ComponentScan;
47 import org.springframework.context.annotation.DependsOn;
48 import org.springframework.scheduling.annotation.EnableScheduling;
49 import org.springframework.web.context.request.RequestContextListener;
52 @SpringBootApplication(scanBasePackages = { "org.onap.music.rest"})
53 @EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class})
54 @ComponentScan(value = {"org.onap.music"})
56 public class MusicApplication extends SpringBootServletInitializer {
59 PropertiesLoader propertyLoader;
62 public static void main(String[] args) {
63 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG","false");
64 System.setProperty("AFT_DME2_CLIENT_KEYSTORE","/opt/app/music/etc/truststore2018.jks");
65 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD","changeit");
66 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS","TLSv1.1,TLSv1.2");
67 new MusicApplication().configure(new SpringApplicationBuilder(MusicApplication.class)).run(args);
71 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
73 return application.sources(MusicApplication.class);
77 @Bean("loadProperties")
78 public void loadProperties() {
79 propertyLoader.loadProperties();
83 private ApplicationContext appContext;
86 @DependsOn("loadProperties")
87 public PropAccess propAccess() {
88 if(MusicUtil.getIsCadi())
89 return new PropAccess(new String[] { "cadi_prop_files=/opt/app/music/etc/cadi.properties" });
94 @Bean(name = "cadiFilter")
95 @DependsOn("loadProperties")
96 public Filter cadiFilter() throws ServletException {
97 propertyLoader.loadProperties();
98 if(MusicUtil.getIsCadi()) {
99 PropAccess propAccess = propAccess();
100 CadiAuthFilter cadiFilter = new CadiAuthFilter(true, propAccess);
103 return (ServletRequest request, ServletResponse response, FilterChain chain) -> {
104 //do nothing for now.
110 @DependsOn("loadProperties")
111 public FilterRegistrationBean<Filter> cadiFilterRegistration() throws ServletException {
112 FilterRegistrationBean<Filter> frb = new FilterRegistrationBean<>();
113 frb.setFilter(cadiFilter());
114 // The Following Patterns are used to control what APIs will be secure
115 // TODO: Make this a configurable item. Build this from an array?
116 if(MusicUtil.getIsCadi()) {
125 frb.addUrlPatterns("/v0/test");
127 frb.setName("cadiFilter");
133 @ConditionalOnMissingBean(RequestContextListener.class)
134 public RequestContextListener requestContextListener() {
135 return new RequestContextListener();