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