remove 2016 logger aspects + verify audit score
[vid.git] / epsdk-app-onap / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.conf;
39
40 import static org.apache.commons.lang3.StringUtils.isNotEmpty;
41
42 import java.util.ArrayList;
43 import java.util.List;
44 import javax.sql.DataSource;
45 import liquibase.integration.spring.SpringLiquibase;
46 import org.onap.portalapp.login.LoginStrategyImpl;
47 import org.onap.portalsdk.core.auth.LoginStrategy;
48 import org.onap.portalsdk.core.conf.AppConfig;
49 import org.onap.portalsdk.core.conf.Configurable;
50 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
51 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
52 import org.onap.portalsdk.core.service.DataAccessService;
53 import org.onap.portalsdk.core.util.CacheManager;
54 import org.onap.portalsdk.core.util.SystemProperties;
55 import org.springframework.beans.factory.annotation.Value;
56 import org.springframework.context.annotation.Bean;
57 import org.springframework.context.annotation.ComponentScan;
58 import org.springframework.context.annotation.Configuration;
59 import org.springframework.context.annotation.DependsOn;
60 import org.springframework.context.annotation.Import;
61 import org.springframework.context.annotation.Profile;
62 import org.springframework.context.annotation.PropertySource;
63 import org.springframework.core.annotation.Order;
64 import org.springframework.scheduling.annotation.EnableAsync;
65 import org.springframework.scheduling.annotation.EnableScheduling;
66 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
67 import org.springframework.scheduling.quartz.SpringBeanJobFactory;
68 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
69 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
70 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
71
72 /**
73  * ONAP Portal SDK sample application. Extends core AppConfig class to
74  * reuse interceptors, view resolvers and other features defined there.
75  */
76 @Configuration
77 @EnableWebMvc
78 @ComponentScan(basePackages = {"org.onap"})
79 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
80 @Profile("src")
81 @EnableAsync
82 @EnableScheduling
83 public class ExternalAppConfig extends AppConfig implements Configurable {
84
85         /** The Constant LOG. */
86     private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
87
88     /**
89      * The Class InnerConfiguration.
90      */
91         @Configuration
92         @Import(SystemProperties.class)
93         static class InnerConfiguration {
94         }
95
96         /**
97          * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
98          */
99         @Override
100         @DependsOn("liquibaseBean")
101         public DataAccessService dataAccessService() {
102                 // Echo the JDBC URL to assist developers when starting the app.
103                 LOG.info("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
104                                 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
105                 return super.dataAccessService();
106         }
107
108         /**
109          * Creates a new list with a single entry that is the external app
110          * definitions.xml path.
111          *
112          * @return List of String, size 1
113          */
114         @Override
115         public List<String> addTileDefinitions() {
116                 List<String> definitions = new ArrayList<>();
117                 definitions.add("/WEB-INF/defs/definitions.xml");
118                 return definitions;
119         }
120
121         /**
122          * Adds request interceptors to the specified registry by calling
123          * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
124          * certain paths from the session timeout interceptor.
125          */
126         @Override
127         public void addInterceptors(InterceptorRegistry registry) {
128                 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
129                                 "/api*", "/single_signon.htm", "/single_signon");
130                 super.addInterceptors(registry);
131         }
132
133         /**
134          * Creates and returns a new instance of a {@link CacheManager} class.
135          *
136          * @return New instance of {@link CacheManager}
137          */
138         @Bean
139         public AbstractCacheManager cacheManager() {
140                 return new CacheManager();
141         }
142
143         /**
144          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
145          * populates it with triggers.
146          *
147          * @return New instance of {@link SchedulerFactoryBean}
148          */
149         @Bean
150         @DependsOn("liquibaseBean")
151         public SchedulerFactoryBean schedulerFactoryBean() {
152                 SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
153                 schedulerFactory.setJobFactory(new SpringBeanJobFactory());
154                 return schedulerFactory;
155         }
156
157
158         @Bean
159         @Order(1)
160         public SpringLiquibase liquibaseBean(DataSource dataSource) {
161                 SpringLiquibase springLiquibase = new SpringLiquibase();
162                 springLiquibase.setDataSource(dataSource);
163                 springLiquibase.setChangeLog("classpath:db-master-changelog.xml");
164                 return springLiquibase;
165         }
166
167         @Bean
168         public LoginStrategy loginStrategy(@Value("${login.strategy.classname:}") String classname) throws ReflectiveOperationException {
169                 return isNotEmpty(classname) ?
170                         newLoginStrategyInstance(classname) : new LoginStrategyImpl();
171         }
172
173         private LoginStrategy newLoginStrategyInstance(String loginStrategyClassname) throws ReflectiveOperationException {
174                 return (LoginStrategy) Class.forName(loginStrategyClassname)
175                         .getConstructor()
176                         .newInstance();
177         }
178
179         @Bean
180         public CommonsMultipartResolver multipartResolver() {
181                 CommonsMultipartResolver resolver=new CommonsMultipartResolver();
182                 resolver.setDefaultEncoding("utf-8");
183                 return resolver;
184         }
185
186 }