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("/static/**").addResourceLocations("/static/");
101 registry.addResourceHandler("/images/**").addResourceLocations("/images/");
102 registry.addResourceHandler("/**").addResourceLocations("/public/");
106 private void init() {
109 MDC.put(MDC_SERVICE_NAME, EPSystemProperties.ECOMP_PORTAL_BE);
110 MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
111 MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
112 MDC.put(MDC_SERVICE_INSTANCE_ID, "");
113 MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.toString());
114 MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
115 } catch (Exception e) {
116 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
123 * @PostConstruct // file://${catalina.home}/conf/log4j.properties public
124 * void initLog4j() throws FileNotFoundException { try { URL[] classpathurls
125 * = ((URLClassLoader)
126 * (Thread.currentThread().getContextClassLoader())).getURLs(); for (URL url
127 * : classpathurls) { System.out.println(url.getFile().toString()); }
128 * Log4jConfigurer.initLogging(
129 * "file://${catalina.home}/conf/log4j.properties"); } catch
130 * (FileNotFoundException e) { ((URLClassLoader)
131 * (Thread.currentThread().getContextClassLoader())).getURLs();
132 * Log4jConfigurer.initLogging("classpath:../conf/log4j.properties"); } } /
135 public DataAccessService dataAccessService() {
136 return super.dataAccessService();
139 public String[] tileDefinitions() {
140 return super.tileDefinitions();
143 public List<String> addTileDefinitions() {
144 List<String> definitions = new ArrayList<String>();
145 definitions.add("/WEB-INF/defs/definitions.xml");
150 public AbstractCacheManager cacheManager() {
151 return new CacheManager();
155 public SessionTimeoutInterceptor sessionTimeoutInterceptor() {
156 return new SessionTimeoutInterceptor();
160 public PortalResourceInterceptor portalResourceInterceptor() {
161 return new PortalResourceInterceptor();
165 public EPLoginService eploginService() {
166 return new EPLoginServiceImpl();
170 public org.openecomp.portalsdk.core.auth.LoginStrategy coreLoginStrategy() {
171 if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
172 return new OpenIdConnectLoginStrategy();
174 return new SimpleLoginStrategy();
178 public LoginStrategy loginStrategy() {
180 if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
181 return new OpenIdConnectLoginStrategy();
183 return new SimpleLoginStrategy();
186 public FnMenuService fnMenuService() {
187 return new FnMenuServiceImpl();
191 public void addInterceptors(InterceptorRegistry registry) {
192 // registry.addInterceptor(new
193 // StaticResourcesInterceptor()).addPathPatterns("/index.htm",
194 // "/applicationsHome", "/widgetsHome", "/admins", "/users",
195 // "/applications", "/widgets");
196 // Excludes login/logout pages and REST endpoints used by other
197 // application servers.
199 registry.addInterceptor(sessionTimeoutInterceptor()).excludePathPatterns("/oid-login", "/portalApi/healthCheck",
200 "/portalApi/healthCheck/", "/portalApi/healthCheckSuspend", "/portalApi/healthCheckSuspend/",
201 "/portalApi/healthCheckResume", "/portalApi/healthCheckResume/", "/login_external",
202 "/login_external.htm*", "login", "/login.htm*", "/auxapi/*", "/context/*", "/api*",
203 "/single_signon.htm", "/single_signon", "/dashboard", "/OpenSourceLogin.htm");
205 registry.addInterceptor(portalResourceInterceptor());
210 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
211 * populates it with triggers.
213 * @return New instance of {@link SchedulerFactoryBean}
217 public EPUebHelper epUebHelper() {
218 return new EPUebHelper();
222 public HealthMonitor healthMonitor() {
223 return new HealthMonitor();
227 * Creates and returns a new instance of a {@link MainUebHandler}.
229 * @return New instance of {@link MainUebHandler}.
232 public MainUebHandler mainUebHandler() {
233 return new MainUebHandler();
237 * Creates and returns a new instance of a {@link InitUebHandler}.
239 * @return New instance of {@link InitUebHandler}.
242 public InitUebHandler initUebHandler() {
243 return new InitUebHandler();
247 * Creates and returns a new instance of a {@link WidgetNotificationHandler}
250 * @return New instance of {@link WidgetNotificationHandler}.
253 public WidgetNotificationHandler widgetNotificationHandler() {
254 return new WidgetNotificationHandler();
258 * Creates and returns a new instance of a {@link FunctionalMenuHandler} .
260 * @return New instance of {@link FunctionalMenuHandler}.
263 public FunctionalMenuHandler functionalMenuHandler() {
264 return new FunctionalMenuHandler();
268 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
269 * populates it with triggers.
271 * @return New instance of {@link SchedulerFactoryBean}
272 * @throws Exception if dataSource fails
274 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
275 @Bean // ANNOTATION COMMENTED OUT
276 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
277 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
278 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
279 scheduler.setDataSource(dataSource());
280 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
281 scheduler.setSchedulerName(getScheduleName());
285 protected String getScheduleName() {
286 final String CRON_SITE_NAME = "cron_site_name";
287 String cronSiteVal = "Default";
289 cronSiteVal = SystemProperties.getProperty(CRON_SITE_NAME);
290 } catch (Exception e) {
291 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
292 logger.warn(EELFLoggerDelegate.errorLogger,
293 "Cron site name not added in property file, using Default value");
296 String cronSiteName = cronSiteVal != null ? cronSiteVal : "";
298 SimpleDateFormat dateFormat = new SimpleDateFormat();
299 dateFormat.applyPattern("YYYYMMdd");
300 String currentDateStr = dateFormat.format(Calendar.getInstance().getTime());
302 return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName;
306 * Sets the scheduler registry adapter.
308 * @param schedulerRegistryAdapter
309 * Scheduler registry adapter
312 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
313 this.schedulerRegistryAdapter = schedulerRegistryAdapter;