nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / conf / ExternalAppConfig.java
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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 static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
23 import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
24 import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
25 import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
26 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
27 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
28
29 import java.net.InetAddress;
30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList;
32 import java.util.Calendar;
33 import java.util.List;
34
35 import javax.annotation.PostConstruct;
36
37 import org.openecomp.portalapp.authentication.LoginStrategy;
38 import org.openecomp.portalapp.authentication.OpenIdConnectLoginStrategy;
39 import org.openecomp.portalapp.authentication.SimpleLoginStrategy;
40 import org.openecomp.portalapp.portal.interceptor.PortalResourceInterceptor;
41 import org.openecomp.portalapp.portal.interceptor.SessionTimeoutInterceptor;
42 import org.openecomp.portalapp.portal.listener.HealthMonitor;
43 import org.openecomp.portalapp.portal.service.EPLoginService;
44 import org.openecomp.portalapp.portal.service.EPLoginServiceImpl;
45 import org.openecomp.portalapp.portal.ueb.EPUebHelper;
46 import org.openecomp.portalapp.portal.utils.EPSystemProperties;
47 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
48 import org.openecomp.portalapp.scheduler.RegistryAdapter;
49 import org.openecomp.portalapp.uebhandler.FunctionalMenuHandler;
50 import org.openecomp.portalapp.uebhandler.InitUebHandler;
51 import org.openecomp.portalapp.uebhandler.MainUebHandler;
52 import org.openecomp.portalapp.uebhandler.WidgetNotificationHandler;
53 import org.openecomp.portalsdk.core.conf.AppConfig;
54 import org.openecomp.portalsdk.core.conf.Configurable;
55 import org.openecomp.portalsdk.core.controller.LogoutController;
56 import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum;
57 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
58 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
59 import org.openecomp.portalsdk.core.service.DataAccessService;
60 import org.openecomp.portalsdk.core.service.FnMenuService;
61 import org.openecomp.portalsdk.core.service.FnMenuServiceImpl;
62 import org.openecomp.portalsdk.core.util.CacheManager;
63 import org.openecomp.portalsdk.core.util.SystemProperties;
64 import org.slf4j.MDC;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.context.annotation.Bean;
67 import org.springframework.context.annotation.ComponentScan;
68 import org.springframework.context.annotation.ComponentScan.Filter;
69 import org.springframework.context.annotation.Configuration;
70 import org.springframework.context.annotation.FilterType;
71 import org.springframework.context.annotation.Profile;
72 import org.springframework.scheduling.annotation.EnableAsync;
73 import org.springframework.scheduling.annotation.EnableScheduling;
74 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
75 import org.springframework.web.servlet.ViewResolver;
76 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
77 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
78 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
79
80 @Configuration
81 @EnableWebMvc
82 @ComponentScan(basePackages = {"org.openecomp"}, excludeFilters = {
83                 @Filter(value = { LogoutController.class }, type = FilterType.ASSIGNABLE_TYPE) })
84 @Profile("src")
85 @EnableAsync
86 @EnableScheduling
87 public class ExternalAppConfig extends AppConfig implements Configurable {
88         
89         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
90
91         private RegistryAdapter schedulerRegistryAdapter;
92
93         public ViewResolver viewResolver() {
94                 return super.viewResolver();
95         }
96
97         @Override
98         public void addResourceHandlers(ResourceHandlerRegistry registry) {
99                 registry.addResourceHandler("/static/**").addResourceLocations("/static/");
100                 registry.addResourceHandler("/images/**").addResourceLocations("/images/");
101                 registry.addResourceHandler("/**").addResourceLocations("/public/");
102         }
103
104         @PostConstruct
105         private void init() {
106                 try {
107                         //Loading defaults
108                         MDC.put(MDC_SERVICE_NAME, EPSystemProperties.ECOMP_PORTAL_BE);
109                         MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
110                         MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
111                         MDC.put(MDC_SERVICE_INSTANCE_ID, "");
112                         MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.toString());
113                         MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
114                 } catch (Exception e) {
115                         logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
116                 }
117         }
118         
119         /*
120          * /
121          * 
122          * @PostConstruct // file://${catalina.home}/conf/log4j.properties public
123          * void initLog4j() throws FileNotFoundException { try { URL[] classpathurls
124          * = ((URLClassLoader)
125          * (Thread.currentThread().getContextClassLoader())).getURLs(); for (URL url
126          * : classpathurls) { System.out.println(url.getFile().toString()); }
127          * Log4jConfigurer.initLogging(
128          * "file://${catalina.home}/conf/log4j.properties"); } catch
129          * (FileNotFoundException e) { ((URLClassLoader)
130          * (Thread.currentThread().getContextClassLoader())).getURLs();
131          * Log4jConfigurer.initLogging("classpath:../conf/log4j.properties"); } } /
132          **/
133
134         public DataAccessService dataAccessService() {
135                 return super.dataAccessService();
136         }
137
138         public String[] tileDefinitions() {
139                 return super.tileDefinitions();
140         }
141
142         public List<String> addTileDefinitions() {
143                 List<String> definitions = new ArrayList<String>();
144                 definitions.add("/WEB-INF/defs/definitions.xml");
145                 return definitions;
146         }
147
148         @Bean
149         public AbstractCacheManager cacheManager() {
150                 return new CacheManager();
151         }
152
153         @Bean
154         public SessionTimeoutInterceptor sessionTimeoutInterceptor() {
155                 return new SessionTimeoutInterceptor();
156         }
157
158         @Bean
159         public PortalResourceInterceptor portalResourceInterceptor() {
160                 return new PortalResourceInterceptor();
161         }
162
163         @Bean
164         public EPLoginService eploginService() {
165                 return new EPLoginServiceImpl();
166         }
167         
168         @Bean
169         public LoginStrategy loginStrategy(){
170                 
171                 if(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
172                         return new OpenIdConnectLoginStrategy();
173                 else
174                         return new SimpleLoginStrategy();
175         }
176         
177         public FnMenuService fnMenuService(){
178                 return new FnMenuServiceImpl();
179         }
180         
181
182         @Override
183         public void addInterceptors(InterceptorRegistry registry) {
184                 // registry.addInterceptor(new
185                 // StaticResourcesInterceptor()).addPathPatterns("/index.htm",
186                 // "/applicationsHome", "/widgetsHome", "/admins", "/users",
187                 // "/applications", "/widgets");
188                 // Excludes login/logout pages and REST endpoints used by other
189                 // application servers.
190                 
191                 
192                 registry.addInterceptor(sessionTimeoutInterceptor()).excludePathPatterns("/oid-login", "/portalApi/healthCheck","/portalApi/healthCheck/",
193                                 "/portalApi/healthCheckSuspend","/portalApi/healthCheckSuspend/", "/portalApi/healthCheckResume","/portalApi/healthCheckResume/",
194                                 "/login_external","/login_external.htm*", "login", "/login.htm*", "/auxapi/*", "/context/*",
195                                 "/api*", "/single_signon.htm", "/single_signon","/dashboard", "/OpenSourceLogin.htm");
196                 
197                 registry.addInterceptor(portalResourceInterceptor());
198                 
199         }
200
201         /**
202          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
203          * populates it with triggers.
204          *
205          * @return New instance of {@link SchedulerFactoryBean}
206          * @throws Exception
207          */
208
209         @Bean
210         public EPUebHelper epUebHelper() {
211                 return new EPUebHelper();
212         }
213
214         @Bean
215         public HealthMonitor healthMonitor() {
216                 return new HealthMonitor();
217         }
218
219         /**
220          * Creates and returns a new instance of a {@link MainUebHandler}.
221          * 
222          * @return New instance of {@link MainUebHandler}.
223          */
224         @Bean
225         public MainUebHandler mainUebHandler() {
226                 return new MainUebHandler();
227         }
228
229         /**
230          * Creates and returns a new instance of a {@link InitUebHandler}.
231          * 
232          * @return New instance of {@link InitUebHandler}.
233          */
234         @Bean
235         public InitUebHandler initUebHandler() {
236                 return new InitUebHandler();
237         }
238
239         /**
240          * Creates and returns a new instance of a {@link WidgetNotificationHandler}
241          * .
242          * 
243          * @return New instance of {@link WidgetNotificationHandler}.
244          */
245         @Bean
246         public WidgetNotificationHandler widgetNotificationHandler() {
247                 return new WidgetNotificationHandler();
248         }
249
250         /**
251          * Creates and returns a new instance of a {@link FunctionalMenuHandler} .
252          * 
253          * @return New instance of {@link FunctionalMenuHandler}.
254          */
255         @Bean
256         public FunctionalMenuHandler functionalMenuHandler() {
257                 return new FunctionalMenuHandler();
258         }
259
260         /**
261          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
262          * populates it with triggers.
263          *
264          * @return New instance of {@link SchedulerFactoryBean}
265          * @throws Exception
266          */
267         // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
268         @Bean // ANNOTATION COMMENTED OUT
269         public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
270                 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
271                 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
272                 scheduler.setDataSource(dataSource());
273                 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
274                 scheduler.setSchedulerName(getScheduleName());
275                 return scheduler;
276         }
277         
278         protected String getScheduleName() {
279                 final String CRON_SITE_NAME = "cron_site_name";
280                 String cronSiteVal = "Default";
281                 try{
282                         cronSiteVal = SystemProperties.getProperty(CRON_SITE_NAME);
283                 } catch (Exception e) {
284                         logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
285                         logger.warn(EELFLoggerDelegate.errorLogger, "Cron site name not added in property file, using Default value");
286                 }
287
288                 String cronSiteName = cronSiteVal != null ? cronSiteVal : "";
289                 
290                 SimpleDateFormat dateFormat = new SimpleDateFormat();
291                 dateFormat.applyPattern("YYYYMMdd");
292                 String currentDateStr = dateFormat.format(Calendar.getInstance().getTime());
293                                 
294                 
295                 return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName;
296         }
297
298
299         /**
300          * Sets the scheduler registry adapter.
301          *
302          * @param schedulerRegistryAdapter
303          */
304         @Autowired
305         public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
306                 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
307         }
308         
309         
310         
311 }