diff options
Diffstat (limited to 'ccsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java')
-rw-r--r-- | ccsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/ccsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java b/ccsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java index d7c9ab7..8e80e79 100644 --- a/ccsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java +++ b/ccsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java @@ -1,6 +1,6 @@ /*- * ================================================================================ - * ECOMP Portal SDK + * DCAE Dashboard * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property * ================================================================================ @@ -35,15 +35,9 @@ import org.onap.portalsdk.core.auth.LoginStrategy; import org.onap.portalsdk.core.command.LoginBean; import org.onap.portalsdk.core.domain.Role; import org.onap.portalsdk.core.domain.RoleFunction; -import org.onap.portalsdk.core.domain.User; -import org.onap.portalsdk.core.domain.FusionObject.Parameters; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.menu.MenuProperties; import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; -import org.onap.portalsdk.core.onboarding.util.CipherUtil; -import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; -import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; -import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.service.LoginService; import org.onap.portalsdk.core.service.RoleService; import org.onap.portalsdk.core.util.SystemProperties; @@ -61,9 +55,10 @@ public class LoginStrategyImpl extends LoginStrategy { @Autowired private RoleService roleService; - + @Override - public ModelAndView doExternalLogin(HttpServletRequest request, HttpServletResponse response) throws IOException { + public ModelAndView doExternalLogin(HttpServletRequest request, HttpServletResponse response) + throws IOException { invalidateExistingSession(request); @@ -72,13 +67,15 @@ public class LoginStrategyImpl extends LoginStrategy { String password = request.getParameter("password"); commandBean.setLoginId(loginId); commandBean.setLoginPwd(password); - //commandBean.setUserid(loginId); + // commandBean.setUserid(loginId); commandBean = loginService.findUser(commandBean, - (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), new HashMap()); + (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), + new HashMap()); List<RoleFunction> roleFunctionList = roleService.getRoleFunctions(loginId); if (commandBean.getUser() == null) { - String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage() + String loginErrorMessage = + (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage() : "login.error.external.invalid - User name and/or password incorrect"; Map<String, String> model = new HashMap<>(); model.put("error", loginErrorMessage); @@ -86,53 +83,55 @@ public class LoginStrategyImpl extends LoginStrategy { } else { // store the currently logged in user's information in the session UserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), - commandBean.getBusinessDirectMenu(), - SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_BACKDOOR), roleFunctionList); + commandBean.getBusinessDirectMenu(), + SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_BACKDOOR), + roleFunctionList); // set the user's max role level in session final String adminRole = "System Administrator"; final String standardRole = "Standard User"; final String readRole = "Read Access"; final String writeRole = "Write Access"; - + String maxRole = ""; String authType = "READ"; String accessLevel = "app"; - - Predicate<Role> adminRoleFilter = + + Predicate<Role> adminRoleFilter = p -> p.getName() != null && p.getName().equalsIgnoreCase(adminRole); - - Predicate<Role> writeRoleFilter = - p -> p.getName() != null && (p.getName().equalsIgnoreCase(writeRole) || p.getName().equalsIgnoreCase(standardRole)); - - Predicate<Role> readRoleFilter = - p -> p.getName() != null && (p.getName().equalsIgnoreCase(readRole) ); + + Predicate<Role> writeRoleFilter = + p -> p.getName() != null && (p.getName().equalsIgnoreCase(writeRole) + || p.getName().equalsIgnoreCase(standardRole)); + + Predicate<Role> readRoleFilter = + p -> p.getName() != null && (p.getName().equalsIgnoreCase(readRole)); if (UserUtils.getUserSession(request) != null) { @SuppressWarnings("unchecked") - Collection<org.onap.portalsdk.core.domain.Role> userRoles = + Collection<org.onap.portalsdk.core.domain.Role> userRoles = UserUtils.getRoles(request).values(); - if (userRoles.stream().anyMatch(adminRoleFilter) ) { + if (userRoles.stream().anyMatch(adminRoleFilter)) { maxRole = "admin"; - } else if (userRoles.stream().anyMatch(writeRoleFilter) ) { + } else if (userRoles.stream().anyMatch(writeRoleFilter)) { maxRole = "write"; - } else if (userRoles.stream().anyMatch(readRoleFilter) ) { + } else if (userRoles.stream().anyMatch(readRoleFilter)) { maxRole = "read"; } - switch(maxRole) { + switch (maxRole) { case "admin": authType = "ADMIN"; accessLevel = "ops"; break; case "write": authType = "WRITE"; - accessLevel = "dev"; + accessLevel = "dev"; break; case "read": authType = "READ"; - accessLevel = "dev"; - break; + accessLevel = "dev"; + break; default: - accessLevel = "app"; + accessLevel = "app"; } } AppUtils.getSession(request).setAttribute("role_level", accessLevel); @@ -142,7 +141,7 @@ public class LoginStrategyImpl extends LoginStrategy { return new ModelAndView("redirect:welcome"); } } - + @Override public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -165,7 +164,7 @@ public class LoginStrategyImpl extends LoginStrategy { return userid; } - private static String getUserIdFromCookie(HttpServletRequest request){ + private static String getUserIdFromCookie(HttpServletRequest request) { String userId = ""; Cookie[] cookies = request.getCookies(); Cookie userIdcookie = null; |