Enhancement to use the common CryptoUtils
[policy/engine.git] / ONAP-SDK-APP / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
1 /*-
2  * ================================================================================
3  * ONAP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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.
18  * ================================================================================
19  */
20
21 package org.onap.portalapp.conf;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.onap.policy.utils.PeCryptoUtils;
26 import org.onap.portalapp.login.LoginStrategyImpl;
27 import org.onap.portalapp.scheduler.RegistryAdapter;
28 import org.onap.portalsdk.core.auth.LoginStrategy;
29 import org.onap.portalsdk.core.conf.AppConfig;
30 import org.onap.portalsdk.core.conf.Configurable;
31 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
33 import org.onap.portalsdk.core.service.DataAccessService;
34 import org.onap.portalsdk.core.util.CacheManager;
35 import org.onap.portalsdk.core.util.SystemProperties;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.Bean;
38 import org.springframework.context.annotation.ComponentScan;
39 import org.springframework.context.annotation.Configuration;
40 import org.springframework.context.annotation.Import;
41 import org.springframework.context.annotation.Profile;
42 import org.springframework.context.annotation.PropertySource;
43 import org.springframework.scheduling.annotation.EnableAsync;
44 import org.springframework.scheduling.annotation.EnableScheduling;
45 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
46 import org.springframework.web.servlet.ViewResolver;
47 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
48 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
49 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
50
51 /**
52  * ONAP Portal SDK sample application. Extends core AppConfig class to reuse interceptors, view resolvers and other
53  * features defined there.
54  */
55 @Configuration
56 @EnableWebMvc
57 @ComponentScan(basePackages = "org.onap")
58 @PropertySource(value = {"${container.classpath:}/WEB-INF/conf/app/test.properties"}, ignoreResourceNotFound = true)
59 @Profile("src")
60 @EnableAsync
61 @EnableScheduling
62 public class ExternalAppConfig extends AppConfig implements Configurable {
63
64     EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
65
66     private RegistryAdapter schedulerRegistryAdapter;
67
68     @Configuration
69     @Import(SystemProperties.class)
70     static class InnerConfiguration {
71     }
72
73     /**
74      * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
75      */
76     @Override
77     public ViewResolver viewResolver() {
78         return super.viewResolver();
79     }
80
81     /**
82      * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
83      *
84      * @param registry
85      */
86     @Override
87     public void addResourceHandlers(ResourceHandlerRegistry registry) {
88         super.addResourceHandlers(registry);
89     }
90
91     /**
92      * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
93      */
94     @Override
95     public DataAccessService dataAccessService() {
96         // Echo the JDBC URL to assist developers when starting the app.
97         System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
98                 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
99         System.setProperty(SystemProperties.DB_PASSWORD,
100                 PeCryptoUtils.decrypt(SystemProperties.getProperty(SystemProperties.DB_PASSWORD)));
101         return super.dataAccessService();
102     }
103
104     /**
105      * Creates a new list with a single entry that is the external app definitions.xml path.
106      *
107      * @return List of String, size 1
108      */
109     @Override
110     public List<String> addTileDefinitions() {
111         List<String> definitions = new ArrayList<>();
112         definitions.add("/WEB-INF/defs/definitions.xml");
113         return definitions;
114     }
115
116     /**
117      * Adds request interceptors to the specified registry by calling
118      * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes certain paths from the session timeout
119      * interceptor.
120      */
121     @Override
122     public void addInterceptors(InterceptorRegistry registry) {
123         super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
124                 "/api*", "/single_signon.htm", "/single_signon");
125         super.addInterceptors(registry);
126     }
127
128     /**
129      * Creates and returns a new instance of a {@link CacheManager} class.
130      *
131      * @return New instance of {@link CacheManager}
132      */
133     @Bean
134     public AbstractCacheManager cacheManager() {
135         return new CacheManager();
136     }
137
138     /**
139      * Creates and returns a new instance of a {@link SchedulerFactoryBean} and populates it with triggers.
140      *
141      * @return New instance of {@link SchedulerFactoryBean}
142      * @throws Exception
143      */
144     // @Bean // ANNOTATION COMMENTED OUT
145     // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
146     public SchedulerFactoryBean schedulerFactoryBean() {
147         SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
148         scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
149         scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
150         try {
151             scheduler.setDataSource(dataSource());
152         } catch (Exception e) {
153             logger.error("Exception occured While Setting DataSource for schedulerfactorybean" + e);
154             return null;
155         }
156         return scheduler;
157     }
158
159     /**
160      * Sets the scheduler registry adapter.
161      *
162      * @param schedulerRegistryAdapter
163      */
164     @Autowired
165     public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
166         this.schedulerRegistryAdapter = schedulerRegistryAdapter;
167     }
168
169     @Bean
170     public LoginStrategy loginStrategy() {
171         return new LoginStrategyImpl();
172     }
173 }