2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.conf;
40 import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
41 import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
42 import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
43 import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
44 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
45 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
47 import java.net.InetAddress;
48 import java.text.SimpleDateFormat;
49 import java.util.ArrayList;
50 import java.util.Calendar;
51 import java.util.List;
53 import javax.annotation.PostConstruct;
55 import org.openecomp.portalapp.authentication.LoginStrategy;
56 import org.openecomp.portalapp.authentication.OpenIdConnectLoginStrategy;
57 import org.openecomp.portalapp.authentication.SimpleLoginStrategy;
58 import org.openecomp.portalapp.controller.core.LogoutController;
59 import org.openecomp.portalapp.controller.core.SDKLoginController;
60 import org.openecomp.portalapp.portal.interceptor.PortalResourceInterceptor;
61 import org.openecomp.portalapp.portal.interceptor.SessionTimeoutInterceptor;
62 import org.openecomp.portalapp.portal.listener.HealthMonitor;
63 import org.openecomp.portalapp.portal.service.EPLoginService;
64 import org.openecomp.portalapp.portal.service.EPLoginServiceImpl;
65 import org.openecomp.portalapp.portal.ueb.EPUebHelper;
66 import org.openecomp.portalapp.portal.utils.EPSystemProperties;
67 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
68 import org.openecomp.portalapp.scheduler.RegistryAdapter;
69 import org.openecomp.portalapp.uebhandler.FunctionalMenuHandler;
70 import org.openecomp.portalapp.uebhandler.InitUebHandler;
71 import org.openecomp.portalapp.uebhandler.MainUebHandler;
72 import org.openecomp.portalapp.uebhandler.WidgetNotificationHandler;
73 import org.openecomp.portalsdk.core.conf.AppConfig;
74 import org.openecomp.portalsdk.core.conf.Configurable;
75 import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum;
76 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
77 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
78 import org.openecomp.portalsdk.core.service.DataAccessService;
79 import org.openecomp.portalsdk.core.service.FnMenuService;
80 import org.openecomp.portalsdk.core.service.FnMenuServiceImpl;
81 import org.openecomp.portalsdk.core.util.CacheManager;
82 import org.openecomp.portalsdk.core.util.SystemProperties;
84 import org.springframework.beans.factory.annotation.Autowired;
85 import org.springframework.context.annotation.Bean;
86 import org.springframework.context.annotation.ComponentScan;
87 import org.springframework.context.annotation.ComponentScan.Filter;
88 import org.springframework.context.annotation.Configuration;
89 import org.springframework.context.annotation.FilterType;
90 import org.springframework.context.annotation.Profile;
91 import org.springframework.scheduling.annotation.EnableAsync;
92 import org.springframework.scheduling.annotation.EnableScheduling;
93 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
94 import org.springframework.web.servlet.ViewResolver;
95 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
96 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
97 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
101 @ComponentScan(basePackages = { "org.openecomp" }, excludeFilters = {
102 @Filter(value = { LogoutController.class, SDKLoginController.class }, type = FilterType.ASSIGNABLE_TYPE) })
106 public class ExternalAppConfig extends AppConfig implements Configurable {
108 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
110 private RegistryAdapter schedulerRegistryAdapter;
112 public ViewResolver viewResolver() {
113 return super.viewResolver();
117 public void addResourceHandlers(ResourceHandlerRegistry registry) {
118 registry.addResourceHandler("/app/fusion/**").addResourceLocations("/app/fusion/");
119 registry.addResourceHandler("/static/**").addResourceLocations("/static/");
120 registry.addResourceHandler("/images/**").addResourceLocations("/images/");
121 registry.addResourceHandler("/**").addResourceLocations("/public/");
125 private void init() {
128 MDC.put(MDC_SERVICE_NAME, EPSystemProperties.ECOMP_PORTAL_BE);
129 MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
130 MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
131 MDC.put(MDC_SERVICE_INSTANCE_ID, "");
132 MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.toString());
133 MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
134 } catch (Exception e) {
135 logger.error(EELFLoggerDelegate.errorLogger, "init failed", e);
142 * @PostConstruct // file://${catalina.home}/conf/log4j.properties public
143 * void initLog4j() throws FileNotFoundException { try { URL[] classpathurls
144 * = ((URLClassLoader)
145 * (Thread.currentThread().getContextClassLoader())).getURLs(); for (URL url
146 * : classpathurls) { System.out.println(url.getFile().toString()); }
147 * Log4jConfigurer.initLogging(
148 * "file://${catalina.home}/conf/log4j.properties"); } catch
149 * (FileNotFoundException e) { ((URLClassLoader)
150 * (Thread.currentThread().getContextClassLoader())).getURLs();
151 * Log4jConfigurer.initLogging("classpath:../conf/log4j.properties"); } } /
154 public DataAccessService dataAccessService() {
155 return super.dataAccessService();
158 public String[] tileDefinitions() {
159 return super.tileDefinitions();
162 public List<String> addTileDefinitions() {
163 List<String> definitions = new ArrayList<String>();
164 definitions.add("/WEB-INF/defs/definitions.xml");
169 public AbstractCacheManager cacheManager() {
170 return new CacheManager();
174 public SessionTimeoutInterceptor sessionTimeoutInterceptor() {
175 return new SessionTimeoutInterceptor();
179 public PortalResourceInterceptor portalResourceInterceptor() {
180 return new PortalResourceInterceptor();
184 public EPLoginService eploginService() {
185 return new EPLoginServiceImpl();
189 public org.openecomp.portalsdk.core.auth.LoginStrategy coreLoginStrategy() {
190 if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
191 return new OpenIdConnectLoginStrategy();
193 return new SimpleLoginStrategy();
197 public LoginStrategy loginStrategy() {
199 if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC"))
200 return new OpenIdConnectLoginStrategy();
202 return new SimpleLoginStrategy();
205 public FnMenuService fnMenuService() {
206 return new FnMenuServiceImpl();
210 public void addInterceptors(InterceptorRegistry registry) {
211 // registry.addInterceptor(new
212 // StaticResourcesInterceptor()).addPathPatterns("/index.htm",
213 // "/applicationsHome", "/widgetsHome", "/admins", "/users",
214 // "/applications", "/widgets");
215 // Excludes login/logout pages and REST endpoints used by other
216 // application servers.
218 registry.addInterceptor(sessionTimeoutInterceptor()).excludePathPatterns("/oid-login", "/portalApi/healthCheck",
219 "/portalApi/healthCheck/", "/portalApi/healthCheckSuspend", "/portalApi/healthCheckSuspend/",
220 "/portalApi/healthCheckResume", "/portalApi/healthCheckResume/", "/login_external",
221 "/login_external.htm*", "login", "/login.htm*","/auxapi/*","/context/*", "/api*",
222 "/single_signon.htm", "/single_signon", "/dashboard", "/OpenSourceLogin.htm");
224 registry.addInterceptor(portalResourceInterceptor());
229 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
230 * populates it with triggers.
232 * @return New instance of {@link SchedulerFactoryBean}
236 public EPUebHelper epUebHelper() {
237 return new EPUebHelper();
241 public HealthMonitor healthMonitor() {
242 return new HealthMonitor();
246 * Creates and returns a new instance of a {@link MainUebHandler}.
248 * @return New instance of {@link MainUebHandler}.
251 public MainUebHandler mainUebHandler() {
252 return new MainUebHandler();
256 * Creates and returns a new instance of a {@link InitUebHandler}.
258 * @return New instance of {@link InitUebHandler}.
261 public InitUebHandler initUebHandler() {
262 return new InitUebHandler();
266 * Creates and returns a new instance of a {@link WidgetNotificationHandler}
269 * @return New instance of {@link WidgetNotificationHandler}.
272 public WidgetNotificationHandler widgetNotificationHandler() {
273 return new WidgetNotificationHandler();
277 * Creates and returns a new instance of a {@link FunctionalMenuHandler} .
279 * @return New instance of {@link FunctionalMenuHandler}.
282 public FunctionalMenuHandler functionalMenuHandler() {
283 return new FunctionalMenuHandler();
287 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
288 * populates it with triggers.
290 * @return New instance of {@link SchedulerFactoryBean}
291 * @throws Exception if dataSource fails
293 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
294 @Bean // ANNOTATION COMMENTED OUT
295 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
296 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
297 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
298 scheduler.setDataSource(dataSource());
299 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
300 scheduler.setSchedulerName(getScheduleName());
304 protected String getScheduleName() {
305 final String CRON_SITE_NAME = "cron_site_name";
306 String cronSiteVal = "Default";
308 cronSiteVal = SystemProperties.getProperty(CRON_SITE_NAME);
309 } catch (Exception e) {
310 logger.error(EELFLoggerDelegate.errorLogger, "getScheduleName failed", e);
311 logger.warn(EELFLoggerDelegate.errorLogger,
312 "Cron site name not added in property file, using Default value");
315 String cronSiteName = cronSiteVal != null ? cronSiteVal : "";
317 SimpleDateFormat dateFormat = new SimpleDateFormat();
318 dateFormat.applyPattern("YYYYMMdd");
319 String currentDateStr = dateFormat.format(Calendar.getInstance().getTime());
321 return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName;
325 * Sets the scheduler registry adapter.
327 * @param schedulerRegistryAdapter
328 * Scheduler registry adapter
331 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
332 this.schedulerRegistryAdapter = schedulerRegistryAdapter;