2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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============================================
38 package org.onap.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.HashMap;
52 import java.util.List;
55 import javax.annotation.PostConstruct;
57 import org.json.JSONArray;
58 import org.json.JSONObject;
59 import org.onap.portalapp.authentication.LoginStrategy;
60 import org.onap.portalapp.authentication.OpenIdConnectLoginStrategy;
61 import org.onap.portalapp.authentication.SimpleLoginStrategy;
62 import org.onap.portalapp.controller.core.LogoutController;
63 import org.onap.portalapp.controller.core.SDKLoginController;
64 import org.onap.portalapp.music.conf.MusicSessionConfig;
65 import org.onap.portalapp.portal.domain.EPApp;
66 import org.onap.portalapp.portal.domain.EPUser;
67 import org.onap.portalapp.portal.domain.EPUserApp;
68 import org.onap.portalapp.portal.interceptor.PortalResourceInterceptor;
69 import org.onap.portalapp.portal.interceptor.SessionTimeoutInterceptor;
70 import org.onap.portalapp.portal.listener.HealthMonitor;
71 import org.onap.portalapp.portal.service.EPLoginService;
72 import org.onap.portalapp.portal.service.EPLoginServiceImpl;
73 import org.onap.portalapp.portal.service.ExternalAccessRolesService;
74 import org.onap.portalapp.portal.service.UserRolesService;
75 import org.onap.portalapp.portal.transport.ExternalAuthUserRole;
76 import org.onap.portalapp.portal.transport.ExternalRoleDescription;
77 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
78 import org.onap.portalapp.portal.utils.EPSystemProperties;
79 import org.onap.portalapp.scheduler.RegistryAdapter;
80 import org.onap.portalapp.uebhandler.FunctionalMenuHandler;
81 import org.onap.portalapp.uebhandler.InitUebHandler;
82 import org.onap.portalapp.uebhandler.MainUebHandler;
83 import org.onap.portalapp.uebhandler.WidgetNotificationHandler;
84 import org.onap.portalsdk.core.conf.AppConfig;
85 import org.onap.portalsdk.core.conf.Configurable;
86 import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
87 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
88 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
89 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
90 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
91 import org.onap.portalsdk.core.service.DataAccessService;
92 import org.onap.portalsdk.core.service.FnMenuService;
93 import org.onap.portalsdk.core.service.FnMenuServiceImpl;
94 import org.onap.portalsdk.core.util.CacheManager;
95 import org.onap.portalsdk.core.util.SystemProperties;
97 import org.springframework.beans.factory.annotation.Autowired;
98 import org.springframework.context.annotation.Bean;
99 import org.springframework.context.annotation.ComponentScan;
100 import org.springframework.context.annotation.ComponentScan.Filter;
101 import org.springframework.context.annotation.Configuration;
102 import org.springframework.context.annotation.FilterType;
103 import org.springframework.context.annotation.Import;
104 import org.springframework.context.annotation.Profile;
105 import org.springframework.scheduling.annotation.EnableAsync;
106 import org.springframework.scheduling.annotation.EnableScheduling;
107 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
108 import org.springframework.web.servlet.ViewResolver;
109 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
110 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
111 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
113 import com.fasterxml.jackson.databind.ObjectMapper;
114 import com.google.gson.Gson;
118 @ComponentScan(basePackages = {"org.onap"}, excludeFilters = {
119 @Filter(value = { LogoutController.class, SDKLoginController.class}, type = FilterType.ASSIGNABLE_TYPE) })
123 @Import({ MusicSessionConfig.class })
124 public class ExternalAppConfig extends AppConfig implements Configurable {
126 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
129 private DataAccessService dataAccessService;
132 private UserRolesService userRolesService;
135 private ExternalAccessRolesService externalAccessRolesService;
137 private RegistryAdapter schedulerRegistryAdapter;
139 String uebAppKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
141 public ViewResolver viewResolver() {
142 return super.viewResolver();
146 public void addResourceHandlers(ResourceHandlerRegistry registry) {
147 registry.addResourceHandler("/app/fusion/**").addResourceLocations("/app/fusion/");
148 registry.addResourceHandler("/static/**").addResourceLocations("/static/");
149 registry.addResourceHandler("/images/**").addResourceLocations("/images/");
150 registry.addResourceHandler("/**").addResourceLocations("/public/");
154 private void init() {
155 String remotecentralizedsystemaccess = SystemProperties.getProperty(EPCommonSystemProperties.REMOTE_CENTRALIZED_SYSTEM_ACCESS);
158 MDC.put(MDC_SERVICE_NAME, EPSystemProperties.ECOMP_PORTAL_BE);
159 MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
160 MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
161 MDC.put(MDC_SERVICE_INSTANCE_ID, "");
162 MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.severity());
163 MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
165 // if("true".equalsIgnoreCase(remotecentralizedsystemaccess)){
166 // importFromExternalAuth();
168 } catch (Exception e) {
169 logger.error(EELFLoggerDelegate.errorLogger, "init failed", e);
174 * Does a sync on functions, roles and role functions based on namespace
175 * for all the centralized applications between AAF and ONAP, updates
176 * fn_user and fn_user_role with user information from AAF.
178 * This is being handled in AAF directly, so it has been deprecated
182 private void importFromExternalAuth() throws Exception {
183 JSONArray aafAppRoles = new JSONArray();
184 JSONArray aafUserList = new JSONArray();
186 //to get all centralized apps
187 List<EPApp> centralizedAppList = dataAccessService.executeNamedQuery("getCentralizedApps", null, null);
188 if(centralizedAppList != null && !centralizedAppList.isEmpty()){
189 for(int i = 0; i < centralizedAppList.size(); i++){
190 //syncRoles(does a sync on functions, roles and role functions)
191 externalAccessRolesService.syncApplicationRolesWithEcompDB(centralizedAppList.get(i));
192 //retrieve roles based on NS
193 aafAppRoles = externalAccessRolesService.getAppRolesJSONFromExtAuthSystem(centralizedAppList.get(i));
194 if(aafAppRoles != null && aafAppRoles.length() > 0){
195 for(int j = 0; j < aafAppRoles.length(); j++){
196 ObjectMapper mapper = new ObjectMapper();
197 String name = aafAppRoles.getJSONObject(j).getString("name");
198 String desc = aafAppRoles.getJSONObject(j).getString("description");
199 ExternalRoleDescription externalRoleDescription = mapper.readValue(desc, ExternalRoleDescription.class);
200 aafUserList = externalAccessRolesService.getAllUsersByRole(name);
201 if(aafUserList != null && aafUserList.length() > 0){
202 for(int k = 0; k < aafUserList.length(); k++){
204 List<EPUser> usersList = null;
205 List<EPUserApp> userRolesList = new ArrayList<>();
206 JSONObject userRole = (JSONObject) aafUserList.get(k);
207 Gson gson = new Gson();
208 ExternalAuthUserRole userRoleObj = gson.fromJson(userRole.toString(), ExternalAuthUserRole.class);
209 if(userRoleObj.getUser() != null){
210 userRoleObj.setUser(userRoleObj.getUser().substring(0, userRoleObj.getUser().indexOf("@")));
212 //for each role and user in that role, check if user exists in fn_user. If not, add
213 Map<String, String> orgUserId = new HashMap<>();
214 orgUserId.put("orgUserIdValue", userRoleObj.getUser());
215 usersList = dataAccessService.executeNamedQuery("epUserAppId", orgUserId, null);
216 if(usersList != null && !usersList.isEmpty()){
217 user = usersList.get(0);
220 // add user to fn_user(needs to be revisited after getting user info from AAF PORTAL-172)
231 public DataAccessService dataAccessService() {
232 return super.dataAccessService();
236 public String[] tileDefinitions() {
237 return super.tileDefinitions();
240 public List<String> addTileDefinitions() {
241 List<String> definitions = new ArrayList<>();
242 definitions.add("/WEB-INF/defs/definitions.xml");
247 public AbstractCacheManager cacheManager() {
248 return new CacheManager();
252 public SessionTimeoutInterceptor sessionTimeoutInterceptor() {
253 return new SessionTimeoutInterceptor();
257 public PortalResourceInterceptor portalResourceInterceptor() {
258 return new PortalResourceInterceptor();
262 public EPLoginService eploginService() {
263 return new EPLoginServiceImpl();
267 public org.onap.portalsdk.core.auth.LoginStrategy coreLoginStrategy() {
268 if ("OIDC".equalsIgnoreCase(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim()))
269 return new OpenIdConnectLoginStrategy();
271 return new SimpleLoginStrategy();
275 public LoginStrategy loginStrategy() {
277 if ("OIDC".equalsIgnoreCase(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim()))
278 return new OpenIdConnectLoginStrategy();
280 return new SimpleLoginStrategy();
283 public FnMenuService fnMenuService() {
284 return new FnMenuServiceImpl();
288 public void addInterceptors(InterceptorRegistry registry) {
289 registry.addInterceptor(sessionTimeoutInterceptor()).excludePathPatterns("/oid-login", "/portalApi/healthCheck",
290 "/portalApi/healthCheck/", "/portalApi/healthCheckSuspend", "/portalApi/healthCheckSuspend/",
291 "/portalApi/healthCheckResume", "/portalApi/healthCheckResume/", "/login_external",
292 "/login_external.htm*", "login", "/login.htm*", "/auxapi/**/*", "/context/*", "/api*",
293 "/single_signon.htm", "/single_signon", "/dashboard", "/OpenSourceLogin.htm");
295 registry.addInterceptor(portalResourceInterceptor());
300 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
301 * populates it with triggers.
303 * @return New instance of {@link SchedulerFactoryBean}
307 public EPUebHelper epUebHelper() {
308 return new EPUebHelper();
312 public HealthMonitor healthMonitor() {
313 return new HealthMonitor();
317 * Creates and returns a new instance of a {@link MainUebHandler}.
319 * @return New instance of {@link MainUebHandler}.
322 public MainUebHandler mainUebHandler() {
323 return new MainUebHandler();
327 * Creates and returns a new instance of a {@link InitUebHandler}.
329 * @return New instance of {@link InitUebHandler}.
332 public InitUebHandler initUebHandler() {
333 return new InitUebHandler();
337 * Creates and returns a new instance of a {@link WidgetNotificationHandler}
340 * @return New instance of {@link WidgetNotificationHandler}.
343 public WidgetNotificationHandler widgetNotificationHandler() {
344 return new WidgetNotificationHandler();
348 * Creates and returns a new instance of a {@link FunctionalMenuHandler} .
350 * @return New instance of {@link FunctionalMenuHandler}.
353 public FunctionalMenuHandler functionalMenuHandler() {
354 return new FunctionalMenuHandler();
358 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
359 * populates it with triggers.
361 * @return New instance of {@link SchedulerFactoryBean}
362 * @throws Exception if dataSource fails
364 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
365 @Bean // ANNOTATION COMMENTED OUT
366 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
367 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
368 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
369 scheduler.setDataSource(dataSource());
370 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
371 scheduler.setSchedulerName(getScheduleName());
375 protected String getScheduleName() {
376 final String CRON_SITE_NAME = "cron_site_name";
377 String cronSiteVal = "Default";
379 cronSiteVal = SystemProperties.getProperty(CRON_SITE_NAME);
380 } catch (Exception e) {
381 logger.error(EELFLoggerDelegate.errorLogger, "getScheduleName failed", e);
382 logger.warn(EELFLoggerDelegate.errorLogger,
383 "Cron site name not added in property file, using Default value");
386 String cronSiteName = cronSiteVal != null ? cronSiteVal : "";
388 SimpleDateFormat dateFormat = new SimpleDateFormat();
389 dateFormat.applyPattern("YYYYMMdd");
390 String currentDateStr = dateFormat.format(Calendar.getInstance().getTime());
392 return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName;
396 * Sets the scheduler registry adapter.
398 * @param schedulerRegistryAdapter
399 * Scheduler registry adapter
402 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
403 this.schedulerRegistryAdapter = schedulerRegistryAdapter;