2 * ================================================================================
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.
18 * ================================================================================
20 package org.openecomp.portalapp.conf;
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;
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;
35 import javax.annotation.PostConstruct;
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;
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;
82 @ComponentScan(basePackages = {"org.openecomp"}, excludeFilters = {
83 @Filter(value = { LogoutController.class }, type = FilterType.ASSIGNABLE_TYPE) })
87 public class ExternalAppConfig extends AppConfig implements Configurable {
89 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
91 private RegistryAdapter schedulerRegistryAdapter;
93 public ViewResolver viewResolver() {
94 return super.viewResolver();
98 public void addResourceHandlers(ResourceHandlerRegistry registry) {
99 registry.addResourceHandler("/static/**").addResourceLocations("/static/");
100 registry.addResourceHandler("/images/**").addResourceLocations("/images/");
101 registry.addResourceHandler("/**").addResourceLocations("/public/");
105 private void init() {
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));
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"); } } /
134 public DataAccessService dataAccessService() {
135 return super.dataAccessService();
138 public String[] tileDefinitions() {
139 return super.tileDefinitions();
142 public List<String> addTileDefinitions() {
143 List<String> definitions = new ArrayList<String>();
144 definitions.add("/WEB-INF/defs/definitions.xml");
149 public AbstractCacheManager cacheManager() {
150 return new CacheManager();
154 public SessionTimeoutInterceptor sessionTimeoutInterceptor() {
155 return new SessionTimeoutInterceptor();
159 public PortalResourceInterceptor portalResourceInterceptor() {
160 return new PortalResourceInterceptor();
164 public EPLoginService eploginService() {
165 return new EPLoginServiceImpl();
169 public LoginStrategy loginStrategy(){
171 if(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
172 return new OpenIdConnectLoginStrategy();
174 return new SimpleLoginStrategy();
177 public FnMenuService fnMenuService(){
178 return new FnMenuServiceImpl();
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.
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");
197 registry.addInterceptor(portalResourceInterceptor());
202 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
203 * populates it with triggers.
205 * @return New instance of {@link SchedulerFactoryBean}
210 public EPUebHelper epUebHelper() {
211 return new EPUebHelper();
215 public HealthMonitor healthMonitor() {
216 return new HealthMonitor();
220 * Creates and returns a new instance of a {@link MainUebHandler}.
222 * @return New instance of {@link MainUebHandler}.
225 public MainUebHandler mainUebHandler() {
226 return new MainUebHandler();
230 * Creates and returns a new instance of a {@link InitUebHandler}.
232 * @return New instance of {@link InitUebHandler}.
235 public InitUebHandler initUebHandler() {
236 return new InitUebHandler();
240 * Creates and returns a new instance of a {@link WidgetNotificationHandler}
243 * @return New instance of {@link WidgetNotificationHandler}.
246 public WidgetNotificationHandler widgetNotificationHandler() {
247 return new WidgetNotificationHandler();
251 * Creates and returns a new instance of a {@link FunctionalMenuHandler} .
253 * @return New instance of {@link FunctionalMenuHandler}.
256 public FunctionalMenuHandler functionalMenuHandler() {
257 return new FunctionalMenuHandler();
261 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
262 * populates it with triggers.
264 * @return New instance of {@link SchedulerFactoryBean}
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());
278 protected String getScheduleName() {
279 final String CRON_SITE_NAME = "cron_site_name";
280 String cronSiteVal = "Default";
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");
288 String cronSiteName = cronSiteVal != null ? cronSiteVal : "";
290 SimpleDateFormat dateFormat = new SimpleDateFormat();
291 dateFormat.applyPattern("YYYYMMdd");
292 String currentDateStr = dateFormat.format(Calendar.getInstance().getTime());
295 return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName;
300 * Sets the scheduler registry adapter.
302 * @param schedulerRegistryAdapter
305 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
306 this.schedulerRegistryAdapter = schedulerRegistryAdapter;