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.controller.core.LogoutController;
41 import org.openecomp.portalapp.controller.core.SDKLoginController;
42 import org.openecomp.portalapp.portal.interceptor.PortalResourceInterceptor;
43 import org.openecomp.portalapp.portal.interceptor.SessionTimeoutInterceptor;
44 import org.openecomp.portalapp.portal.listener.HealthMonitor;
45 import org.openecomp.portalapp.portal.service.EPLoginService;
46 import org.openecomp.portalapp.portal.service.EPLoginServiceImpl;
47 import org.openecomp.portalapp.portal.ueb.EPUebHelper;
48 import org.openecomp.portalapp.portal.utils.EPSystemProperties;
49 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
50 import org.openecomp.portalapp.scheduler.RegistryAdapter;
51 import org.openecomp.portalapp.uebhandler.FunctionalMenuHandler;
52 import org.openecomp.portalapp.uebhandler.InitUebHandler;
53 import org.openecomp.portalapp.uebhandler.MainUebHandler;
54 import org.openecomp.portalapp.uebhandler.WidgetNotificationHandler;
55 import org.openecomp.portalsdk.core.conf.AppConfig;
56 import org.openecomp.portalsdk.core.conf.Configurable;
57 import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum;
58 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
59 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
60 import org.openecomp.portalsdk.core.service.DataAccessService;
61 import org.openecomp.portalsdk.core.service.FnMenuService;
62 import org.openecomp.portalsdk.core.service.FnMenuServiceImpl;
63 import org.openecomp.portalsdk.core.util.CacheManager;
64 import org.openecomp.portalsdk.core.util.SystemProperties;
66 import org.springframework.beans.factory.annotation.Autowired;
67 import org.springframework.context.annotation.Bean;
68 import org.springframework.context.annotation.ComponentScan;
69 import org.springframework.context.annotation.ComponentScan.Filter;
70 import org.springframework.context.annotation.Configuration;
71 import org.springframework.context.annotation.FilterType;
72 import org.springframework.context.annotation.Profile;
73 import org.springframework.scheduling.annotation.EnableAsync;
74 import org.springframework.scheduling.annotation.EnableScheduling;
75 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
76 import org.springframework.web.servlet.ViewResolver;
77 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
78 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
79 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
83 @ComponentScan(basePackages = { "org.openecomp" }, excludeFilters = {
84 @Filter(value = { LogoutController.class, SDKLoginController.class }, type = FilterType.ASSIGNABLE_TYPE) })
88 public class ExternalAppConfig extends AppConfig implements Configurable {
90 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
92 private RegistryAdapter schedulerRegistryAdapter;
94 public ViewResolver viewResolver() {
95 return super.viewResolver();
99 public void addResourceHandlers(ResourceHandlerRegistry registry) {
100 registry.addResourceHandler("/app/fusion/**").addResourceLocations("/app/fusion/");
101 registry.addResourceHandler("/static/**").addResourceLocations("/static/");
102 registry.addResourceHandler("/images/**").addResourceLocations("/images/");
103 registry.addResourceHandler("/**").addResourceLocations("/public/");
107 private void init() {
110 MDC.put(MDC_SERVICE_NAME, EPSystemProperties.ECOMP_PORTAL_BE);
111 MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
112 MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
113 MDC.put(MDC_SERVICE_INSTANCE_ID, "");
114 MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.toString());
115 MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
116 } catch (Exception e) {
117 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
124 * @PostConstruct // file://${catalina.home}/conf/log4j.properties public
125 * void initLog4j() throws FileNotFoundException { try { URL[] classpathurls
126 * = ((URLClassLoader)
127 * (Thread.currentThread().getContextClassLoader())).getURLs(); for (URL url
128 * : classpathurls) { System.out.println(url.getFile().toString()); }
129 * Log4jConfigurer.initLogging(
130 * "file://${catalina.home}/conf/log4j.properties"); } catch
131 * (FileNotFoundException e) { ((URLClassLoader)
132 * (Thread.currentThread().getContextClassLoader())).getURLs();
133 * Log4jConfigurer.initLogging("classpath:../conf/log4j.properties"); } } /
136 public DataAccessService dataAccessService() {
137 return super.dataAccessService();
140 public String[] tileDefinitions() {
141 return super.tileDefinitions();
144 public List<String> addTileDefinitions() {
145 List<String> definitions = new ArrayList<String>();
146 definitions.add("/WEB-INF/defs/definitions.xml");
151 public AbstractCacheManager cacheManager() {
152 return new CacheManager();
156 public SessionTimeoutInterceptor sessionTimeoutInterceptor() {
157 return new SessionTimeoutInterceptor();
161 public PortalResourceInterceptor portalResourceInterceptor() {
162 return new PortalResourceInterceptor();
166 public EPLoginService eploginService() {
167 return new EPLoginServiceImpl();
171 public org.openecomp.portalsdk.core.auth.LoginStrategy coreLoginStrategy() {
172 if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
173 return new OpenIdConnectLoginStrategy();
175 return new SimpleLoginStrategy();
179 public LoginStrategy loginStrategy() {
181 if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
182 return new OpenIdConnectLoginStrategy();
184 return new SimpleLoginStrategy();
187 public FnMenuService fnMenuService() {
188 return new FnMenuServiceImpl();
192 public void addInterceptors(InterceptorRegistry registry) {
193 // registry.addInterceptor(new
194 // StaticResourcesInterceptor()).addPathPatterns("/index.htm",
195 // "/applicationsHome", "/widgetsHome", "/admins", "/users",
196 // "/applications", "/widgets");
197 // Excludes login/logout pages and REST endpoints used by other
198 // application servers.
200 registry.addInterceptor(sessionTimeoutInterceptor()).excludePathPatterns("/oid-login", "/portalApi/healthCheck",
201 "/portalApi/healthCheck/", "/portalApi/healthCheckSuspend", "/portalApi/healthCheckSuspend/",
202 "/portalApi/healthCheckResume", "/portalApi/healthCheckResume/", "/login_external",
203 "/login_external.htm*", "login", "/login.htm*", "/auxapi/*", "/context/*", "/api*",
204 "/single_signon.htm", "/single_signon", "/dashboard", "/OpenSourceLogin.htm");
206 registry.addInterceptor(portalResourceInterceptor());
211 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
212 * populates it with triggers.
214 * @return New instance of {@link SchedulerFactoryBean}
218 public EPUebHelper epUebHelper() {
219 return new EPUebHelper();
223 public HealthMonitor healthMonitor() {
224 return new HealthMonitor();
228 * Creates and returns a new instance of a {@link MainUebHandler}.
230 * @return New instance of {@link MainUebHandler}.
233 public MainUebHandler mainUebHandler() {
234 return new MainUebHandler();
238 * Creates and returns a new instance of a {@link InitUebHandler}.
240 * @return New instance of {@link InitUebHandler}.
243 public InitUebHandler initUebHandler() {
244 return new InitUebHandler();
248 * Creates and returns a new instance of a {@link WidgetNotificationHandler}
251 * @return New instance of {@link WidgetNotificationHandler}.
254 public WidgetNotificationHandler widgetNotificationHandler() {
255 return new WidgetNotificationHandler();
259 * Creates and returns a new instance of a {@link FunctionalMenuHandler} .
261 * @return New instance of {@link FunctionalMenuHandler}.
264 public FunctionalMenuHandler functionalMenuHandler() {
265 return new FunctionalMenuHandler();
269 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
270 * populates it with triggers.
272 * @return New instance of {@link SchedulerFactoryBean}
273 * @throws Exception if dataSource fails
275 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
276 @Bean // ANNOTATION COMMENTED OUT
277 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
278 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
279 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
280 scheduler.setDataSource(dataSource());
281 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
282 scheduler.setSchedulerName(getScheduleName());
286 protected String getScheduleName() {
287 final String CRON_SITE_NAME = "cron_site_name";
288 String cronSiteVal = "Default";
290 cronSiteVal = SystemProperties.getProperty(CRON_SITE_NAME);
291 } catch (Exception e) {
292 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
293 logger.warn(EELFLoggerDelegate.errorLogger,
294 "Cron site name not added in property file, using Default value");
297 String cronSiteName = cronSiteVal != null ? cronSiteVal : "";
299 SimpleDateFormat dateFormat = new SimpleDateFormat();
300 dateFormat.applyPattern("YYYYMMdd");
301 String currentDateStr = dateFormat.format(Calendar.getInstance().getTime());
303 return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName;
307 * Sets the scheduler registry adapter.
309 * @param schedulerRegistryAdapter
310 * Scheduler registry adapter
313 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
314 this.schedulerRegistryAdapter = schedulerRegistryAdapter;