diff options
Diffstat (limited to 'ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller')
12 files changed, 1142 insertions, 0 deletions
diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/ECOMPLogoutController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/ECOMPLogoutController.java new file mode 100644 index 00000000..13242c2e --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/ECOMPLogoutController.java @@ -0,0 +1,112 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.logging.aop.EPAuditLog; +import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog; +import org.openecomp.portalapp.portal.utils.EPSystemProperties; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +public class ECOMPLogoutController extends EPUnRestrictedBaseController{ + + private EPUser user; + private static final String EP_SERVICE = "EPService"; + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECOMPLogoutController.class); + + @EPAuditLog + @RequestMapping(value = {"/logout.htm" }, method = RequestMethod.GET) + public ModelAndView logOut(HttpServletRequest request, + HttpServletResponse response) throws Exception { + + ModelAndView modelView = null; + + chatRoomLogout(request); + logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Logout request received."); + + modelView = new ModelAndView("redirect:login.htm"); + + /** + if (UserUtils.isClientMobileDevice(request)){ + modelView.setViewName(modelView.getViewName().concat("?viewType=mobile")); + } + */ + String cookieDoamin = EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN); + Cookie epCookie = new Cookie(EP_SERVICE, ""); + epCookie.setMaxAge(0); + epCookie.setDomain(cookieDoamin); + epCookie.setPath("/"); + + Cookie appHeaderCookie = new Cookie("show_app_header", ""); + appHeaderCookie.setMaxAge(0); + appHeaderCookie.setDomain(cookieDoamin); + appHeaderCookie.setPath("/"); + + Cookie appTabCookie = new Cookie("cookieTabs", ""); + appTabCookie.setMaxAge(0); + appTabCookie.setDomain(cookieDoamin); + appTabCookie.setPath("/"); + + Cookie appVisInvisTabCookie = new Cookie("visInVisCookieTabs", ""); + appVisInvisTabCookie.setMaxAge(0); + appVisInvisTabCookie.setDomain(cookieDoamin); + appVisInvisTabCookie.setPath("/"); + + response.addCookie(epCookie); + response.addCookie(appHeaderCookie); + response.addCookie(appTabCookie); + response.addCookie(appVisInvisTabCookie); + request.getSession().invalidate(); + + logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Successfully processed the logout request."); + + return modelView; + } + + @EPMetricsLog + public void chatRoomLogout(HttpServletRequest request){ + request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); + setUser(EPUserUtils.getUserSession(request)); + } + + public EPUser getUser() { + return user; + } + + public void setUser(EPUser user) { + this.user = user; + } +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPFusionBaseController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPFusionBaseController.java new file mode 100644 index 00000000..f34fd078 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPFusionBaseController.java @@ -0,0 +1,106 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.controller.FusionBaseController; +import org.openecomp.portalsdk.core.domain.MenuData; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public abstract class EPFusionBaseController extends FusionBaseController { + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPFusionBaseController.class); + + + + @Override + public boolean isAccessible() { + return true; + } + + public boolean isRESTfulCall() { + return true; + } + + @ModelAttribute("menu") + public Map<String, Object> messages(HttpServletRequest request) { + HttpSession session = null; + Map<String, Object> model = new HashMap<String, Object>(); + session = request.getSession(); + EPUser user = EPUserUtils.getUserSession(request); + if (session != null && user != null) { + @SuppressWarnings("unchecked") + Set<MenuData> menuResult = (Set<MenuData>) session + .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)); + try { + model = setMenu(menuResult); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + } + } + + return model; + } + + public Map<String, Object> setMenu(Set<MenuData> menuResult) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + List<List<MenuData>> childItemList = new ArrayList<List<MenuData>>(); + ; + List<MenuData> parentList = new ArrayList<MenuData>(); + ; + Map<String, Object> model = new HashMap<String, Object>(); + for (MenuData menu : menuResult) { + MenuData parentData = new MenuData(); + parentData.setLabel(menu.getLabel()); + parentData.setAction(menu.getAction()); + parentData.setImageSrc(menu.getImageSrc()); + parentList.add(parentData); + List<MenuData> tempList = new ArrayList<MenuData>(); + for (Object o : menu.getChildMenus()) { + MenuData m = (MenuData) o; + MenuData data = new MenuData(); + data.setLabel(m.getLabel()); + data.setAction(m.getAction()); + data.setImageSrc(m.getImageSrc()); + tempList.add(data); + } + childItemList.add(tempList); + } + model.put("childItemList", childItemList != null ? mapper.writeValueAsString(childItemList) : ""); + model.put("parentList", parentList != null ? mapper.writeValueAsString(parentList) : ""); + return model; + } +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPRestrictedBaseController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPRestrictedBaseController.java new file mode 100644 index 00000000..286678cc --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPRestrictedBaseController.java @@ -0,0 +1,52 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +public class EPRestrictedBaseController extends EPFusionBaseController{ + + protected String viewName; + private String exceptionView; + + @Override + public boolean isAccessible() { + return false; + } + + @Override + public boolean isRESTfulCall(){ + return false; + } + + protected String getViewName() { + return viewName; + } + + protected void setViewName(String viewName) { + this.viewName = viewName; + } + + public String getExceptionView() { + return (exceptionView == null) ? "runtime_error_handler" : exceptionView; + } + + public void setExceptionView(String exceptionView) { + this.exceptionView = exceptionView; + } +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPRestrictedRESTfulBaseController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPRestrictedRESTfulBaseController.java new file mode 100644 index 00000000..69504a13 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPRestrictedRESTfulBaseController.java @@ -0,0 +1,54 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +public class EPRestrictedRESTfulBaseController extends EPFusionBaseController{ + + protected String viewName; + private String exceptionView; + + @Override + public boolean isAccessible() { + return false; + } + + @Override + public boolean isRESTfulCall(){ + return true; + } + + protected String getViewName() { + return viewName; + } + + protected void setViewName(String viewName) { + this.viewName = viewName; + } + + public String getExceptionView() { + return (exceptionView == null) ? "runtime_error_handler" : exceptionView; + } + + public void setExceptionView(String exceptionView) { + this.exceptionView = exceptionView; + } + + +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPUnRestrictedBaseController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPUnRestrictedBaseController.java new file mode 100644 index 00000000..7f23ce4c --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/EPUnRestrictedBaseController.java @@ -0,0 +1,42 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +public class EPUnRestrictedBaseController extends EPFusionBaseController{ + protected String viewName; + + @Override + public boolean isAccessible() { + return true; + } + + @Override + public boolean isRESTfulCall(){ + return false; + } + + protected String getViewName() { + return viewName; + } + + protected void setViewName(String viewName) { + this.viewName = viewName; + } +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/LoginController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/LoginController.java new file mode 100644 index 00000000..632f9178 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/LoginController.java @@ -0,0 +1,356 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; + +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.portalapp.command.EPLoginBean; +import org.openecomp.portalapp.portal.domain.SharedContext; +import org.openecomp.portalapp.portal.service.EPLoginService; +import org.openecomp.portalapp.portal.service.SharedContextService; +import org.openecomp.portalapp.portal.utils.EPSystemProperties; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalapp.service.EPProfileService; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalapp.util.SessionCookieUtil; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.menu.MenuProperties; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalTimeoutHandler; +import org.openecomp.portalsdk.core.util.CipherUtil; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.AppUtils; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.util.StopWatch; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.util.WebUtils; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/") +public class LoginController extends EPUnRestrictedBaseController implements LoginService{ + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginController.class); + + public static final String DEFAULT_SUCCESS_VIEW = "applicationsHome"; + public static final String DEFAULT_FAILURE_VIEW = "login"; + public static final String ERROR_MESSAGE_KEY = "error"; + public static final String REDIRECT_URL = "redirectUrl"; + + @Autowired + EPProfileService service; + @Autowired + private EPLoginService loginService; + @Autowired + private SharedContextService sharedContextService; + + String viewName = "login"; + private String welcomeView; + + public String getWelcomeView() { + return welcomeView; + } + + public void setWelcomeView(String welcomeView) { + this.welcomeView = welcomeView; + } + + @RequestMapping(value = {"/login.htm" }, method = RequestMethod.GET) + public ModelAndView login(HttpServletRequest request, HttpServletResponse response) { + Map<String, Object> model = new HashMap<String, Object>(); + + String authentication = SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM); + + String loginPage; + + if (authentication == null || authentication.equals("") || authentication.trim().equals("OIDC")) + loginPage = "openIdLogin"; + else + loginPage = getViewName(); + + return new ModelAndView(loginPage,"model", model); + } + + @SuppressWarnings("rawtypes") + @RequestMapping(value = {"/open_source/login" }, method = RequestMethod.POST) + public @ResponseBody String loginValidate(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + EPLoginBean commandBean = new EPLoginBean(); + String loginId = root.get("loginId").textValue(); + String password = root.get("password").textValue(); + commandBean.setLoginId(loginId); + commandBean.setLoginPwd(CipherUtil.encrypt(password)); + HashMap additionalParamsMap = new HashMap(); + StringBuilder sbAdditionalInfo = new StringBuilder(); + + commandBean = getLoginService().findUser(commandBean, (String)request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), + additionalParamsMap); + String fullURL = EPUserUtils.getFullURL(request); + if (commandBean.getUser() == null) { + String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage() + : "login.error.external.invalid"; + + logger.info(EELFLoggerDelegate.debugLogger, "loginId = " + loginId + " does not exist in the the DB."); + logger.info(EELFLoggerDelegate.errorLogger, "loginId = " + loginId + " does not exist in the the DB."); + sbAdditionalInfo.append(String.format("But the Login-Id: %s doesn't exist in the Database. Request-URL: %s", + loginId, fullURL)); + return loginErrorMessage; + } + else { + // store the currently logged in user's information in the session + EPUserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), commandBean.getBusinessDirectMenu(), + null); + + try{ + logger.info(EELFLoggerDelegate.debugLogger, "******************* store user info into share context begins"); + String sessionId = request.getSession().getId(); + List<SharedContext> existingSC = getSharedContextService().getSharedContexts(sessionId); + if(existingSC==null || existingSC.size()==0){ + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_FIRST_NAME, commandBean.getUser().getFirstName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_LAST_NAME, commandBean.getUser().getLastName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_EMAIL, commandBean.getUser().getEmail()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_ORG_USERID, commandBean.getLoginId()); + } + + }catch(Exception e){ + logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + logger.info(EELFLoggerDelegate.errorLogger, "failed the shared context adding process " + e.getMessage()); + logger.info(EELFLoggerDelegate.debugLogger, "********************** failed the shared context adding process " + e.getMessage()); + } + logger.info(EELFLoggerDelegate.debugLogger, "********************* PresetUp the EP service cookie and intial sessionManagement"); + + SessionCookieUtil.preSetUp(request, response); + SessionCookieUtil.setUpUserIdCookie(request, response, loginId); + + JSONObject j = new JSONObject("{success: success}"); + + return j.toString(); + + } + + } + + @RequestMapping(value = {"/processSingleSignOn" }, method = RequestMethod.GET) + public ModelAndView processSingelSignOn(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Map<Object, Object> model = new HashMap<Object, Object>(); + HashMap<Object, Object> additionalParamsMap = new HashMap<Object, Object>(); + EPLoginBean commandBean = new EPLoginBean(); + MDC.put(MDC_KEY_REQUEST_ID, EPUserUtils.getRequestId(request)); + String orgUserId = ""; + //get userId from cookie + orgUserId = SessionCookieUtil.getUserIdFromCookie(request, response); + logger.info(EELFLoggerDelegate.debugLogger, "******************** process_singelSignOn process begins"); + logger.info(EELFLoggerDelegate.debugLogger, "******************* We get the orgUserId " + orgUserId); + + StringBuilder sbAdditionalInfo = new StringBuilder(); + if ((orgUserId == null || orgUserId.length() == 0)) { + model.put(ERROR_MESSAGE_KEY, SystemProperties.MESSAGE_KEY_LOGIN_ERROR_COOKIE_EMPTY); + if(request.getParameter("redirectUrl")!=null && request.getParameter("redirectUrl").length()!=0){ + return new ModelAndView("redirect:" + DEFAULT_FAILURE_VIEW + ".htm" + "?redirectUrl=" + request.getParameter("redirectUrl")); + }else{ + return new ModelAndView("redirect:" + DEFAULT_FAILURE_VIEW + ".htm"); + } + } + else { + + StopWatch stopWatch = new StopWatch("LoginController.Login"); + stopWatch.start(); + + try { + logger.info(EELFLoggerDelegate.metricsLogger, "Operation findUser is started to locate " + orgUserId + " in the database."); + logger.info(EELFLoggerDelegate.debugLogger, "Operation findUser is started to locate " + orgUserId + " in the database."); + commandBean.setLoginId(orgUserId); + commandBean.setOrgUserId(orgUserId); + commandBean = getLoginService().findUserWithoutPassword(commandBean, (String)request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), additionalParamsMap); + + stopWatch.stop(); + MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms"); + logger.info(EELFLoggerDelegate.metricsLogger, "Operation findUser is completed."); + logger.info(EELFLoggerDelegate.debugLogger, "Operation findUser is completed."); + } catch(Exception e) { + stopWatch.stop(); + MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms"); + logger.info(EELFLoggerDelegate.errorLogger, "Exception occurred while performing findUser " + orgUserId + ". Details: " + EcompPortalUtils.getStackTrace(e)); + logger.info(EELFLoggerDelegate.debugLogger, "Exception occurred while performing findUser " + orgUserId + ". Details: " + EcompPortalUtils.getStackTrace(e)); + logger.info(EELFLoggerDelegate.metricsLogger, "Operation findUser is failed."); + } finally { + MDC.remove(EPSystemProperties.MDC_TIMER); + } + + sbAdditionalInfo.append("Login attempt is succeeded. "); + String fullURL = EPUserUtils.getFullURL(request); + if (commandBean.getUser() == null) { + logger.info(EELFLoggerDelegate.debugLogger, "loginId = " + orgUserId + " does not exist in the the DB."); + logger.info(EELFLoggerDelegate.errorLogger, "loginId = " + orgUserId + " does not exist in the the DB."); + logger.info(EELFLoggerDelegate.debugLogger, "loginId = " + orgUserId + " does not exist in the the DB."); + + sbAdditionalInfo.append(String.format("But the Login-Id: %s doesn't exist in the Database. Created a Guest Session. Request-URL: %s", + orgUserId, fullURL)); + if(request.getParameter("redirectUrl")!=null && request.getParameter("redirectUrl").length()!=0){ + return new ModelAndView("redirect:" + DEFAULT_FAILURE_VIEW + ".htm" + "?redirectUrl=" + request.getParameter("redirectUrl")); + }else{ + return new ModelAndView("redirect:" + DEFAULT_FAILURE_VIEW + ".htm"); + } + } + else { + + sbAdditionalInfo.append(String.format("Login-Id: %s, Login-Method: %s, Request-URL: %s", orgUserId, "", fullURL)); + logger.info(EELFLoggerDelegate.debugLogger, "*********************** now set up user session for " + orgUserId); + + EPUserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), commandBean.getBusinessDirectMenu(), ""); + logger.info(EELFLoggerDelegate.debugLogger, "*********************** now set up user session for " + orgUserId + " finished"); + + //Store user's information into share context + try{ + logger.info(EELFLoggerDelegate.debugLogger, "******************* store user info into share context begins"); + + String sessionId = request.getSession().getId(); + List<SharedContext> existingSC = getSharedContextService().getSharedContexts(sessionId); + if(existingSC==null || existingSC.size()==0){ + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_FIRST_NAME, commandBean.getUser().getFirstName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_LAST_NAME, commandBean.getUser().getLastName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_EMAIL, commandBean.getUser().getEmail()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_ORG_USERID, commandBean.getLoginId()); + } + + }catch(Exception e){ + logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + logger.info(EELFLoggerDelegate.errorLogger, "failed the shared context adding process " + e.getMessage()); + logger.info(EELFLoggerDelegate.debugLogger, "********************** failed the shared context adding process " + e.getMessage()); + + } + + logger.info(EELFLoggerDelegate.debugLogger, "********************* PresetUp the EP service cookie and intial sessionManagement"); + + SessionCookieUtil.preSetUp(request, response); + SessionCookieUtil.setUpUserIdCookie(request, response, orgUserId); + logger.info(EELFLoggerDelegate.debugLogger, "********************* PresetUp the EP service cookie and intial sessionManagement completed"); + logger.info(EELFLoggerDelegate.errorLogger, commandBean.getUser().getOrgUserId() + " exists in the the system."); + logger.info(EELFLoggerDelegate.debugLogger, commandBean.getUser().getOrgUserId() + " exists in the the system."); + + String redirect = "redirectUrl"; + + //get redirectUrl from URL parameter + if(request.getParameter(redirect)!=null && request.getParameter(redirect).length()!=0){ + String forwardUrl = URLDecoder.decode(request.getParameter(redirect),"UTF-8"); + //clean cookie + Cookie cookie2 = new Cookie(redirect, ""); + cookie2.setMaxAge(0); + cookie2.setDomain(EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN)); + cookie2.setPath("/"); + response.addCookie(cookie2); + return new ModelAndView("redirect:" + forwardUrl); + } + + //first check if redirectUrl exists or not + if(WebUtils.getCookie(request, redirect)!=null){ + String forwardUrl = WebUtils.getCookie(request, redirect).getValue(); + //clean cookie + Cookie cookie2 = new Cookie(redirect, ""); + cookie2.setMaxAge(0); + cookie2.setDomain(EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN)); + cookie2.setPath("/"); + response.addCookie(cookie2); + + return new ModelAndView("redirect:" + forwardUrl); + } + } + } + + // if user has been authenticated, now take them to the welcome page. + //return new ModelAndView("redirect:" + DEFAULT_SUCCESS_VIEW + ".htm"); + logger.info(EELFLoggerDelegate.debugLogger, "********************** Now return to application home page"); + + return new ModelAndView("redirect:" + SystemProperties.getProperty(EPSystemProperties.FE_URL)); + + // + // Re-enable for BE/FE separation. For 1607, at last minute we decided to go out + // without BE/FE separation. + // + //return new ModelAndView("redirect:" + SystemProperties.getProperty(EPSystemProperties.FE_URL)); + + } + + public String getJessionId(HttpServletRequest request){ + + return request.getSession().getId(); + /* + Cookie ep = WebUtils.getCookie(request, JSESSIONID); + if(ep==null){ + return request.getSession().getId(); + } + return ep.getValue(); + */ + } + + + protected void initateSessionMgtHandler(HttpServletRequest request) { + String jSessionId = getJessionId(request); + PortalTimeoutHandler.sessionCreated(jSessionId, jSessionId, AppUtils.getSession(request)); + } + + + public String getViewName() { + return viewName; + } + public void setViewName(String viewName) { + this.viewName = viewName; + } + public EPLoginService getLoginService() { + return loginService; + } + + public void setLoginService(EPLoginService loginService) { + this.loginService = loginService; + } + + public SharedContextService getSharedContextService() { + return sharedContextService; + } + + public void setSharedContextService(SharedContextService sharedContextService) { + this.sharedContextService = sharedContextService; + } + + + +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/LoginService.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/LoginService.java new file mode 100644 index 00000000..f69916a0 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/LoginService.java @@ -0,0 +1,36 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +public interface LoginService { + + public ModelAndView login(HttpServletRequest request, HttpServletResponse response); + + public @ResponseBody String loginValidate(HttpServletRequest request, HttpServletResponse response) throws Exception; + + public ModelAndView processSingelSignOn(HttpServletRequest request, HttpServletResponse response) throws Exception; + +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/OpenCollaborationController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/OpenCollaborationController.java new file mode 100644 index 00000000..e360cce8 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/OpenCollaborationController.java @@ -0,0 +1,48 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/") +public class OpenCollaborationController extends RestrictedBaseController{ + + @RequestMapping(value = {"/opencollaboration" }, method = RequestMethod.GET) + public ModelAndView view(HttpServletRequest request) { + Map<String, Object> model = new HashMap<String, Object>(); + EPUser user = (EPUser) EPUserUtils.getUserSession(request); + + model.put("name",(user.getFirstName() + " " + (user.getLastName() != null? user.getLastName().substring(0,1): "" ))); + return new ModelAndView("collaboration","model", model); + } + +}
\ No newline at end of file diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/PeerBroadcastSocket.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/PeerBroadcastSocket.java new file mode 100644 index 00000000..92dc9294 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/PeerBroadcastSocket.java @@ -0,0 +1,106 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.io.IOException; +import java.util.Hashtable; +import java.util.Map; + +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import com.fasterxml.jackson.databind.ObjectMapper; + +@ServerEndpoint("/opencontact") +public class PeerBroadcastSocket { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PeerBroadcastSocket.class); + + public static Map<String, Object> channelMap = new Hashtable<String, Object>(); + public Map<String, String> sessionMap = new Hashtable<String, String>(); + ObjectMapper mapper = new ObjectMapper(); + + @OnMessage + public void message(String message, Session session) { + try { + // JSONObject jsonObject = new JSONObject(message); + @SuppressWarnings("unchecked") + Map<String, Object> jsonObject = mapper.readValue(message, Map.class); + try { + Object from = jsonObject.get("from"); + if (from != null) { + if(channelMap.get(from.toString()) == null) { + channelMap.put(from.toString(), session); + sessionMap.put(session.getId(), from.toString()); + } + } + } catch (Exception je) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to read value" + je.getMessage()); + } + + try { + Object to = jsonObject.get("to"); + if (to == null) + return; + Object toSessionObj = channelMap.get(to); + if (toSessionObj != null) { + Session toSession = null; + toSession = (Session) toSessionObj; + toSession.getBasicRemote().sendText(message); + } + + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to send text" + ex.getMessage()); + } + + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed" + ex.getMessage()); + } + + } + + @OnOpen + public void open(Session session) { + logger.info(EELFLoggerDelegate.debugLogger, "Channel opened"); + } + + @OnClose + public void close(Session session) { + String channel = sessionMap.get(session.getId()); + if (channel != null) { + Object sessObj = channelMap.get(channel); + if (sessObj != null) { + try { + ((Session) sessObj).close(); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to close" + e.getMessage()); + } + } + channelMap.remove(channel); + } + logger.info(EELFLoggerDelegate.debugLogger, "Channel closed"); + } + +} + diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java new file mode 100644 index 00000000..d7e50ebf --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java @@ -0,0 +1,77 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalapp.portal.logging.aop.EPAuditLog; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalapp.service.EPProfileService; +import org.openecomp.portalsdk.core.domain.Profile; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +public class UserProfileController extends EPRestrictedBaseController { + + @Autowired + EPProfileService service; + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserProfileController.class); + + @RequestMapping(value = {"/user_profile" }, method = RequestMethod.GET) + public ModelAndView ProfileSearch(HttpServletRequest request) { + Map<String, Object> model = new HashMap<String, Object>(); + ObjectMapper mapper = new ObjectMapper(); + + try { + List<Profile> profileList = service.findAll(); + model.put("customerInfo", mapper.writeValueAsString(profileList)); + } catch (JsonGenerationException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Encountered an JsonGenerationException while performing the ProfileSearch, Details:" + EcompPortalUtils.getStackTrace(e)); + } catch (JsonMappingException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Encountered an JsonMappingException while performing the ProfileSearch, Details:" + EcompPortalUtils.getStackTrace(e)); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Encountered an IOException while performing the ProfileSearch, Details:" + EcompPortalUtils.getStackTrace(e)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "Encountered an Exception while performing the ProfileSearch, Details:" + EcompPortalUtils.getStackTrace(e)); + } + + return new ModelAndView("user_profile", "model", model); + } +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java new file mode 100644 index 00000000..264f0f59 --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java @@ -0,0 +1,89 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.security.Principal; +import java.util.Set; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority; +import org.openecomp.portalapp.portal.logging.aop.EPAuditLog; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +public class WelcomeController extends EPRestrictedBaseController{ + String viewName; + + @RequestMapping(value = {"/welcome" }, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + return new ModelAndView(getViewName()); + } + + @RequestMapping(value = "/index.htm", method = RequestMethod.GET) + public String getIndexPage(HttpServletRequest request) { + return "/index"; + } + + @RequestMapping(value = {"/applicationsHome", "/dashboard", "/widgetsHome", "/kpidash*", "/admins", "/users", "/portalAdmins", "/applications", "/widgets", "/functionalMenu", "/contactUs", "/getAccess","/appCatalog" }, method = RequestMethod.GET) + public String getEcompSinglePage(HttpServletRequest request, HttpServletResponse response) { + return "forward:/index.html"; + } + + protected String getViewName() { + return viewName; + } + + protected void setViewName(String viewName) { + this.viewName = viewName; + } + + + @Resource(name = "namedAdmins") + private Set<SubjectIssuerGrantedAuthority> admins; + + @RequestMapping("/user") + public String user(Principal p) { + return "oid-user"; + } + + @RequestMapping("/admin") + public String admin(Model model, Principal p) { + + model.addAttribute("admins", admins); + + return "oid-admin"; + } + @RequestMapping("/oid-login") + public ModelAndView login(Principal p) { + return new ModelAndView("openIdLogin"); + } +} diff --git a/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/sessionmgt/SessionCommunicationController.java b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/sessionmgt/SessionCommunicationController.java new file mode 100644 index 00000000..0348fb8d --- /dev/null +++ b/ecomp-portal-BE/src/main/java/org/openecomp/portalapp/controller/sessionmgt/SessionCommunicationController.java @@ -0,0 +1,64 @@ +/*- + * ================================================================================ + * eCOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller.sessionmgt; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openecomp.portalapp.controller.EPRestrictedRESTfulBaseController; +import org.openecomp.portalapp.portal.logging.aop.EPAuditLog; +import org.openecomp.portalapp.service.sessionmgt.ManageService; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("/auxapi") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +public class SessionCommunicationController extends EPRestrictedRESTfulBaseController { + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SessionCommunicationController.class); + + @Autowired + ManageService manageService; + + protected boolean isAuxRESTfulCall(){ + return true; + } + + @RequestMapping(value={"/getSessionSlotCheckInterval"}, method = RequestMethod.GET, produces = "application/json") + public Integer getSessionSlotCheckInterval(HttpServletRequest request, HttpServletResponse response) throws Exception { + return manageService.fetchSessionSlotCheckInterval(); + } + + @RequestMapping(value={"/extendSessionTimeOuts"}, method = RequestMethod.POST) + public Boolean extendSessionTimeOuts(HttpServletRequest request, HttpServletResponse response, @RequestParam String sessionMap) throws Exception { + manageService.extendSessionTimeOuts(sessionMap); + + return true; + } + +} |