From 3e7145fc12ed8475ba10bb2a3c63004d41aa42bc Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Fri, 7 Jul 2017 07:21:10 -0400 Subject: [PORTAL-25] Role Centralization Bump EP SDK version to 1.3.0-SNAPSHOT Support Role Centralization & Common Set of Roles across All ONAP On-Boarded Applications Change-Id: Icfc1bbfddaf2c7c7176b4cf7bb7017d853c63100 Signed-off-by: Christopher Lott (cl778h) --- .../core/service/AccessConfiguration.java | 132 ++++++++++++ .../core/service/CentralAccessCondition.java | 30 +++ .../core/service/LocalAccessCondition.java | 19 ++ .../portalsdk/core/service/LoginService.java | 18 ++ .../core/service/LoginServiceCentralizedImpl.java | 221 +++++++++++++++++++++ .../portalsdk/core/service/LoginServiceImpl.java | 9 +- .../portalsdk/core/service/ProfileService.java | 30 ++- .../service/ProfileServiceCentralizedImpl.java | 73 +++++++ .../portalsdk/core/service/ProfileServiceImpl.java | 3 - .../core/service/RestApiRequestBuilder.java | 136 +++++++++++++ .../portalsdk/core/service/RoleService.java | 101 +++++++++- .../core/service/RoleServiceCentralizedAccess.java | 169 ++++++++++++++++ .../portalsdk/core/service/RoleServiceImpl.java | 30 ++- .../core/service/UrlAccessCentalizedImpl.java | 77 +++++++ .../portalsdk/core/service/UrlAccessImpl.java | 48 +++++ .../portalsdk/core/service/UrlAccessService.java | 15 ++ .../service/UserProfileServiceCentalizedImpl.java | 137 +++++++++++++ .../core/service/UserProfileServiceImpl.java | 4 +- 18 files changed, 1210 insertions(+), 42 deletions(-) create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java create mode 100644 ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service') diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java new file mode 100644 index 00000000..ae6bd309 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/AccessConfiguration.java @@ -0,0 +1,132 @@ +package org.openecomp.portalsdk.core.service; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AccessConfiguration { + + + + /** + * + * @returns RoleServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public RoleService roleServiceImpl() { + return new RoleServiceImpl(); + } + + + /** + * + * @returns RoleServiceCentralizedAccess bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public RoleService roleServiceCentralizedAccess() { + return new RoleServiceCentralizedAccess(); + } + + + /** + * + * @returns LoginServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public LoginService loginServiceImpl() { + return new LoginServiceImpl(); + } + + + /** + * + * @returns LoginServiceCentralizedImpl bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public LoginService loginServiceCEntralizedImpl() { + return new LoginServiceCentralizedImpl(); + } + + /** + * + * @returns UserProfileServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public UserProfileService userProfileServiceImpl() { + return new UserProfileServiceImpl(); + } + + + /** + * + * @returns returns UserProfileServiceCentalizedImpl bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public UserProfileService userProfileServiceCentalizedImpl() { + return new UserProfileServiceCentalizedImpl(); + } + + + + /** + * + * @returns returns ProfileServiceImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public ProfileService profileServiceImpl() { + return new ProfileServiceImpl(); + } + + + /** + * + * @returns returns ProfileServiceCentralizedImpl bean if CentralAccessCondition is true + */ + + @Bean + @Conditional(CentralAccessCondition.class) + public ProfileService profileServiceCentralizedImpl() { + return new ProfileServiceCentralizedImpl(); + } + + /** + * + * @returns returns UrlAccessCentalizedImpl bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public UrlAccessService userUtilsCentalizedImpl() { + return new UrlAccessCentalizedImpl(); + } + + + /** + * + * @returns returns UrlAccessImpl bean if LocalAccessCondition is true + */ + @Bean + @Conditional(LocalAccessCondition.class) + public UrlAccessService urlAccessImpl() { + return new UrlAccessImpl(); + } + + + /** + * + * @returns returns RestApiRequestBuilder bean if CentralAccessCondition is true + */ + @Bean + @Conditional(CentralAccessCondition.class) + public RestApiRequestBuilder restApiRequestBuilder() { + return new RestApiRequestBuilder(); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java new file mode 100644 index 00000000..9cefd5e1 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/CentralAccessCondition.java @@ -0,0 +1,30 @@ +package org.openecomp.portalsdk.core.service; + +import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + + +public class CentralAccessCondition implements Condition { + + /** + * returns true if the application is centralized + */ + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + boolean isRemote = false; + + if(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) == null) + { + isRemote = false; + } + else if(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) != null && PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED).equals("remote")){ + isRemote = true; + } + + return isRemote; + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java new file mode 100644 index 00000000..68a9626a --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LocalAccessCondition.java @@ -0,0 +1,19 @@ +package org.openecomp.portalsdk.core.service; + +import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.springframework.context.annotation.Condition; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +public class LocalAccessCondition implements Condition{ + + /** + * returns true if the application is not centralized + */ + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + return PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) == null || (PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED) != null && ! PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED).equals("remote")); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java index 4f004108..5baa86ef 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginService.java @@ -27,10 +27,28 @@ import org.openecomp.portalsdk.core.command.*; public interface LoginService { + /** + * + * @param bean + * @param menuPropertiesFilename + * @param additionalParams + * @return returns login user bean + * @throws Exception + */ // validate user exists in the system @SuppressWarnings("rawtypes") LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams) throws Exception; + + /** + * + * @param bean + * @param menuPropertiesFilename + * @param additionalParams + * @param matchPassword + * @return returns login user bean + * @throws Exception + */ @SuppressWarnings("rawtypes") LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams, boolean matchPassword) throws Exception; } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java new file mode 100644 index 00000000..45eff80c --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceCentralizedImpl.java @@ -0,0 +1,221 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.openecomp.portalsdk.core.command.LoginBean; +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.domain.UserApp; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.menu.MenuBuilder; +import org.openecomp.portalsdk.core.service.support.FusionService; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.AppUtils; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class LoginServiceCentralizedImpl extends FusionService implements LoginService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginServiceCentralizedImpl.class); + + @Autowired + AppService appService; + + @Autowired + private DataAccessService dataAccessService; + + @Autowired + RestApiRequestBuilder restApiRequestBuilder; + + @SuppressWarnings("unused") + private MenuBuilder menuBuilder; + + @Override + public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams) + throws Exception { + return findUser(bean, menuPropertiesFilename, additionalParams, true); + } + + @SuppressWarnings("rawtypes") + public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, HashMap additionalParams, + boolean matchPassword) throws Exception { + User user = null; + User userCopy = null; + + if (bean.getUserid() != null && bean.getUserid() != null) { + user = (User) findUser(bean); + } else { + if (matchPassword) + user = (User) findUser(bean.getLoginId(), bean.getLoginPwd()); + else + user = (User) findUserWithoutPwd(bean.getLoginId()); + } + + if (user != null) { + + if (AppUtils.isApplicationLocked() + && !UserUtils.hasRole(user, SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID))) { + bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_APPLICATION_LOCKED); + } + + // raise an error if the user is inactive + if (!user.getActive()) { + bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE); + } + + if (!userHasActiveRoles(user)) { + bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE); + } + // only login the user if no errors have occurred + if (bean.getLoginErrorMessage() == null) { + + // this will be a snapshot of the user's information as + // retrieved from the database + userCopy = (User) user.clone(); + + User appuser = getUser(userCopy); + + appuser.setLastLoginDate(new Date()); + + // update the last logged in date for the user + // user.setLastLoginDate(new Date()); + getDataAccessService().saveDomainObject(appuser, additionalParams); + + // update the audit log of the user + // Check for the client device type and set log attributes + // appropriately + + // save the above changes to the User and their audit trail + + // create the application menu based on the user's privileges + + Set appMenu = getMenuBuilder().getMenu( + SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME), dataAccessService); + bean.setMenu(appMenu != null ? appMenu : new HashSet()); + System.out.println(appMenu); + Set businessDirectMenu = getMenuBuilder().getMenu( + SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_SET_NAME), + dataAccessService); + bean.setBusinessDirectMenu(businessDirectMenu != null ? businessDirectMenu : new HashSet()); + + bean.setUser(userCopy); + } + } + + return bean; + } + + private boolean userHasActiveRoles(User user) { + boolean hasActiveRole = false; + Iterator roles = user.getRoles().iterator(); + while (roles.hasNext()) { + Role role = (Role) roles.next(); + if (role.getActive()) { + hasActiveRole = true; + break; + } + } + return hasActiveRole; + } + + @SuppressWarnings("null") + public User findUser(LoginBean bean) throws Exception { + + User user = null; + + ObjectMapper mapper = new ObjectMapper(); + HashSet rolefun = null; + + String repsonse = restApiRequestBuilder.getViaREST("/getUser/" + bean.getUserid(), true, bean.getUserid()); + + user = mapper.readValue(repsonse, User.class); + + @SuppressWarnings("unchecked") + Set setAppsObj = user.getUserApps(); + + Iterator it = setAppsObj.iterator(); + while (it.hasNext()) { + Object next = it.next(); + + UserApp nextApp = mapper.convertValue(next, UserApp.class); + rolefun = new HashSet<>(); + Role role = nextApp.getRole(); + + Set roleFunctionList = role.getRoleFunctions(); + Set roleFunctionListNew = new HashSet<>(); + Iterator itetaror = roleFunctionList.iterator(); + while (itetaror.hasNext()) { + Object nextValue = itetaror.next(); + RoleFunction roleFunction = mapper.convertValue(nextValue, RoleFunction.class); + roleFunctionListNew.add(roleFunction); + } + + role.setRoleFunctions(roleFunctionListNew); + nextApp.setRole(role); + nextApp.getRole().getRoleFunctions(); + SortedSet UserAppSet = new TreeSet<>(); + UserAppSet.add(nextApp); + user.setUserApps(UserAppSet); + } + + return user; + } + + public User findUser(String loginId, String password) { + + List list = null; + + StringBuffer criteria = new StringBuffer(); + criteria.append(" where login_id = '").append(loginId).append("'").append(" and login_pwd = '").append(password) + .append("'"); + + list = getDataAccessService().getList(User.class, criteria.toString(), null, null); + return (list == null || list.size() == 0) ? null : (User) list.get(0); + } + + private User findUserWithoutPwd(String loginId) { + List list = null; + StringBuffer criteria = new StringBuffer(); + criteria.append(" where login_id = '").append(loginId).append("'"); + list = getDataAccessService().getList(User.class, criteria.toString(), null, null); + return (list == null || list.size() == 0) ? null : (User) list.get(0); + } + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + public MenuBuilder getMenuBuilder() { + return new MenuBuilder(); + } + + public void setMenuBuilder(MenuBuilder menuBuilder) { + this.menuBuilder = menuBuilder; + } + + public User getUser(User user) { + List list = null; + + StringBuffer criteria = new StringBuffer(); + criteria.append(" where login_id = '").append(user.getLoginId()).append("'"); + + list = getDataAccessService().getList(User.class, criteria.toString(), null, null); + return (list == null || list.size() == 0) ? null : (User) list.get(0); + + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java index e0a4b7c6..a38a16ff 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/LoginServiceImpl.java @@ -29,17 +29,14 @@ import java.util.Set; import org.openecomp.portalsdk.core.command.LoginBean; import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.domain.UserApp; import org.openecomp.portalsdk.core.menu.MenuBuilder; import org.openecomp.portalsdk.core.service.support.FusionService; import org.openecomp.portalsdk.core.util.SystemProperties; import org.openecomp.portalsdk.core.web.support.AppUtils; import org.openecomp.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("loginService") @Transactional public class LoginServiceImpl extends FusionService implements LoginService { @@ -113,9 +110,6 @@ public class LoginServiceImpl extends FusionService implements LoginService { // save the above changes to the User and their audit trail - - - // create the application menu based on the user's privileges Set appMenu = getMenuBuilder().getMenu(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME),dataAccessService); @@ -133,7 +127,8 @@ public class LoginServiceImpl extends FusionService implements LoginService { private boolean userHasActiveRoles(User user) { boolean hasActiveRole = false; - Iterator roles = user.getRoles().iterator(); + @SuppressWarnings("rawtypes") + Iterator roles = user.getRoles().iterator(); while (roles.hasNext()) { Role role = (Role)roles.next(); if (role.getActive()) { diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java index 61bd3b6e..3eda4cfc 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileService.java @@ -26,11 +26,35 @@ import org.openecomp.portalsdk.core.domain.User; public interface ProfileService { - List findAll(); - Profile getProfile(int id); + /** + * + * @return returns list of profiles + * @throws Exception + */ + List findAll() throws Exception; - User getUser(String id); + /** + * + * @param id + * @return returns profile of requested ID + * @throws Exception + */ + Profile getProfile(int id) throws Exception; + + /** + * + * @param id loginId + * @return returns User info of requested ID + * @throws Exception + */ + User getUser(String id) throws Exception; + + /** + * + * @param user + *saveUser method saves the user object + */ void saveUser(User user); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java new file mode 100644 index 00000000..c4da3338 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceCentralizedImpl.java @@ -0,0 +1,73 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.List; + +import org.openecomp.portalsdk.core.domain.Profile; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + +public class ProfileServiceCentralizedImpl implements ProfileService{ + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ProfileServiceCentralizedImpl.class); + + @Autowired + AppService appService; + + @Autowired + private DataAccessService dataAccessService; + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + @Autowired + RestApiRequestBuilder restApiRequestBuilder ; + + @Override + public List findAll() throws Exception{ + + List profileList =null; + ObjectMapper mapper = new ObjectMapper(); + + String user = restApiRequestBuilder.getViaREST("/findAllProfiles", true,null); + profileList = mapper.readValue(user, + TypeFactory.defaultInstance().constructCollectionType(List.class, Profile.class)); + return profileList; + } + + @Override + public Profile getProfile(int id) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + Profile user = null; + String responseString = restApiRequestBuilder.getViaREST("/getProfile/" + id, true,Integer.toString(id)); + user = mapper.readValue(responseString, Profile.class); + return user; + } + + @Override + public User getUser(String id) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + User user = new User(); + String responseString =restApiRequestBuilder.getViaREST("/getUser/" + id, true,id); + user = mapper.readValue(responseString, User.class); + + return user; + } + + @Override + public void saveUser(User user) { + try { + getDataAccessService().saveDomainObject(user, null); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveUser failed", e); + } + } +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java index 2d6fcfee..e0785567 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/ProfileServiceImpl.java @@ -24,12 +24,9 @@ import java.util.List; import org.openecomp.portalsdk.core.dao.ProfileDao; import org.openecomp.portalsdk.core.domain.Profile; import org.openecomp.portalsdk.core.domain.User; -import org.openecomp.portalsdk.core.service.DataAccessService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("profileService") @Transactional public class ProfileServiceImpl implements ProfileService{ diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java new file mode 100644 index 00000000..6a2f7a47 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RestApiRequestBuilder.java @@ -0,0 +1,136 @@ +package org.openecomp.portalsdk.core.service; + +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; + +import org.openecomp.portalsdk.core.domain.App; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.rest.RestWebServiceClient; +import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; + +public class RestApiRequestBuilder { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleServiceCentralizedAccess.class); + + @Autowired + AppService appService; + + public static String content_type = "application/json"; + + public String getViaREST(String restEndPoint, boolean isBasicAuth,String userId) { + String appName = ""; + String requestId = ""; + String appUserName = ""; + String decryptedPwd = ""; + + logger.info(EELFLoggerDelegate.debugLogger, "Making use of REST API communication for GET" + restEndPoint); + + App app = appService.getDefaultApp(); + + if (app != null) { + appName = app.getName(); + appUserName = app.getUsername(); + try { + decryptedPwd = CipherUtil.decrypt(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + + e.toString()); + } + } else { + logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database."); + appName = SystemProperties.SDK_NAME; + } + requestId = MDC.get(MDC_KEY_REQUEST_ID); + + String response = null; + try { + response = RestWebServiceClient.getInstance().getPortalContent(restEndPoint, userId,appName, requestId, appUserName, + decryptedPwd, isBasicAuth); + } catch (Exception ex) { + response = "Failed to get roles " + ex.toString(); + } + logger.debug(EELFLoggerDelegate.debugLogger, "getRoles response: {}", response); + return response; + } + + public void postViaREST(String restEndPoint, boolean isBasicAuth, String content,String userId) { + String appName = ""; + String requestId = ""; + String appUserName = ""; + String decryptedPwd = ""; + + logger.info(EELFLoggerDelegate.debugLogger, "Making use of REST API communication for POST" + restEndPoint); + + App app = appService.getDefaultApp(); + + if (app != null) { + appName = app.getName(); + appUserName = app.getUsername(); + try { + decryptedPwd = CipherUtil.decrypt(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + + e.toString()); + } + } else { + logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database."); + appName = SystemProperties.SDK_NAME; + } + requestId = MDC.get(MDC_KEY_REQUEST_ID); + + + try { + RestWebServiceClient.getInstance().postPortalContent(restEndPoint, userId, appName, requestId, appUserName, + decryptedPwd, content_type, content, isBasicAuth); + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.debugLogger, "POST response: {}", ex); + } + logger.debug(EELFLoggerDelegate.debugLogger, "POST response: {}"); + + } + + public void deleteViaRest(String restEndPoint, boolean isBasicAuth, String content, String filter , String userId) { + String appName = ""; + String requestId = ""; + String appUserName = ""; + String decryptedPwd = ""; + + logger.info(EELFLoggerDelegate.debugLogger, "Making use of REST API communication for DELETE" + restEndPoint); + + App app = appService.getDefaultApp(); + + if (app != null) { + appName = app.getName(); + appUserName = app.getUsername(); + try { + decryptedPwd = CipherUtil.decrypt(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, + "Exception occurred in WebServiceCallServiceImpl.get while decrypting the password. Details: " + + e.toString()); + } + } else { + logger.warn(EELFLoggerDelegate.errorLogger, "Unable to locate the app information from the database."); + appName = SystemProperties.SDK_NAME; + } + requestId = MDC.get(MDC_KEY_REQUEST_ID); + + + try { + RestWebServiceClient.getInstance().deletePortalContent(restEndPoint, userId, appName, requestId, appUserName, + decryptedPwd, content_type, content, isBasicAuth, filter); + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.debugLogger, "DELETE response: {}", ex); + } + logger.debug(EELFLoggerDelegate.debugLogger, "DELETE response: {}"); + + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java index 01367ecd..f05adf64 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleService.java @@ -26,25 +26,104 @@ import org.openecomp.portalsdk.core.domain.RoleFunction; public interface RoleService { - List getRoleFunctions(); + /** + * + * @param requestedLoginId loginId + * @return returns List of RoleFunction + * @throws Exception + * Method getRoleFunctions returns list of Role Functions + */ + List getRoleFunctions(String requestedLoginId) throws Exception; - List getAvailableChildRoles(Long roleId); - Role getRole(Long id); + /** + * + * @param requestedLoginId + * @param roleId + * @return returns List of Role + * @throws Exception + * Method getAvailableChildRoles returns list of avialable child roles + */ + List getAvailableChildRoles(String requestedLoginId,Long roleId) throws Exception; - void saveRole(Role domainRole); - void deleteRole(Role domainRole); + /** + * + * @param requestedLoginId + * @param id roleId + * @return returns role + * @throws Exception + * Method getRole returns Role object if requested roleID + */ + Role getRole(String requestedLoginId,Long id) throws Exception; - List getAvailableRoles(); + /** + * + * @param requestedLoginId + * @param domainRole Object to be saved + * Method saveRole saves the Role Object + */ + void saveRole(String requestedLoginId,Role domainRole); - List getActiveRoles(); + /** + * + * @param requestedLoginId + * @param domainRole Object to be removed + * Method deleteRole deletes the requested Role Object + */ + void deleteRole(String requestedLoginId,Role domainRole); + + /** + * + * @param requestedLoginId + * @return returns list of available roles + * @throws Exception + * Method getAvailableRoles gets the list of available roles + */ + + List getAvailableRoles(String requestedLoginId) throws Exception; + + /** + * + * @param requestedLoginId + * @return + * @throws Exception + * Method getActiveRoles gets the list of active roles of application + * + */ + List getActiveRoles(String requestedLoginId) throws Exception; - RoleFunction getRoleFunction(String code); + /** + * + * @param requestedLoginId + * @param code function code + * @return + * @throws Exception + * Method getRoleFunction returns RoleFunction of requested function code + */ + RoleFunction getRoleFunction(String requestedLoginId,String code) throws Exception; - void saveRoleFunction(RoleFunction domainRoleFunction); + /** + * + * @param requestedLoginId + * @param domainRoleFunction + * Method saveRoleFunction saves the requested RoleFunction object + */ + void saveRoleFunction(String requestedLoginId,RoleFunction domainRoleFunction); - void deleteRoleFunction(RoleFunction domainRoleFunction); + /** + * + * @param requestedLoginId + * @param domainRoleFunction + * Method deleteRoleFunction deletes the requested RoleFunction object + */ + void deleteRoleFunction(String requestedLoginId,RoleFunction domainRoleFunction); - void deleteDependcyRoleRecord(Long id); + /** + * + * @param requestedLoginId + * @param id + * Method deleteDependcyRoleRecord deletes the requested object + */ + void deleteDependcyRoleRecord(String requestedLoginId,Long id); } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java new file mode 100644 index 00000000..f507a7fc --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceCentralizedAccess.java @@ -0,0 +1,169 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + +@Transactional +public class RoleServiceCentralizedAccess implements RoleService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RoleServiceCentralizedAccess.class); + + @Autowired + AppService appService; + + @Autowired + RestApiRequestBuilder restApiRequestBuilder; + + @Override + public List getRoleFunctions(String loginId) throws Exception { + + List roleFunctionList = null; + String role_function_list = ""; + role_function_list = restApiRequestBuilder.getViaREST("/getAllRoleFunctions", true, loginId); + ObjectMapper mapper = new ObjectMapper(); + roleFunctionList = mapper.readValue(role_function_list, + TypeFactory.defaultInstance().constructCollectionType(List.class, RoleFunction.class)); + return roleFunctionList; + } + + @Override + public List getAvailableChildRoles(String loginId, Long roleId) throws Exception { + List availableChildRoles = getAvailableRoles(loginId); + if (roleId == null || roleId == 0) { + return availableChildRoles; + } + + Role currentRole = getRole(loginId, roleId); + Set allParentRoles = new TreeSet(); + allParentRoles = getAllParentRolesAsList(loginId, currentRole, allParentRoles); + + Iterator availableChildRolesIterator = availableChildRoles.iterator(); + while (availableChildRolesIterator.hasNext()) { + Role role = availableChildRolesIterator.next(); + if (!role.getActive() || allParentRoles.contains(role) || role.getId().equals(roleId)) { + availableChildRolesIterator.remove(); + } + } + return availableChildRoles; + } + + @SuppressWarnings("unchecked") + private Set getAllParentRolesAsList(String loginId, Role role, Set allParentRoles) { + Set parentRoles = role.getParentRoles(); + allParentRoles.addAll(parentRoles); + Iterator parentRolesIterator = parentRoles.iterator(); + while (parentRolesIterator.hasNext()) { + getAllParentRolesAsList(loginId, parentRolesIterator.next(), allParentRoles); + } + return allParentRoles; + } + + @Override + public Role getRole(String loginId, Long id) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + + String roleString = restApiRequestBuilder.getViaREST("/role/" + id, true, loginId); + Role role = null; + + role = mapper.readValue(roleString, Role.class); + + logger.info(EELFLoggerDelegate.applicationLogger, "role_id" + role.getId()); + return role; + + } + + @Override + public void saveRole(String loginId, Role domainRole) { + try { + restApiRequestBuilder.postViaREST("/saveRole", true, domainRole.toString(), loginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveRole Failed", e); + } + } + + @Override + public void deleteRole(String loginId, Role domainRole) { + + String filter = " where active_yn = 'Y' "; + try { + restApiRequestBuilder.deleteViaRest("/deleteRole", true, domainRole.toString(), filter, loginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteRole Failed", e); + } + } + + @Override + public List getAvailableRoles(String requestedLoginId) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + + String roleList = restApiRequestBuilder.getViaREST("/getRoles", true, requestedLoginId); + List roles = null; + roles = mapper.readValue(roleList, + TypeFactory.defaultInstance().constructCollectionType(List.class, Role.class)); + return roles; + } + + @Override + public List getActiveRoles(String requestedLoginId) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + String roleString = restApiRequestBuilder.getViaREST("/activeRoles?active_yn = 'Y'", true, requestedLoginId); + List roles = null; + roles = mapper.readValue(roleString, + TypeFactory.defaultInstance().constructCollectionType(List.class, Role.class)); + return roles; + + } + + @Override + public RoleFunction getRoleFunction(String requestedLoginId, String code) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + String responseString = restApiRequestBuilder.getViaREST("/getRoleFunction/" + code, true, requestedLoginId); + RoleFunction roleFunction = null; + roleFunction = mapper.readValue(responseString, RoleFunction.class); + return roleFunction; + } + + @Override + public void saveRoleFunction(String requestedLoginId, RoleFunction domainRoleFunction) { + try { + restApiRequestBuilder.postViaREST("/saveRoleFunction", true, domainRoleFunction.toString(), + requestedLoginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveRoleFunction Failed", e); + } + } + + @Override + public void deleteRoleFunction(String requestedLoginId, RoleFunction domainRoleFunction) { + + try { + restApiRequestBuilder.deleteViaRest("/deleteRoleFucntion", true, domainRoleFunction.toString(), null, + requestedLoginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteRoleFunction Failed", e); + } + } + + @Override + public void deleteDependcyRoleRecord(String requestedLoginId, Long id) { + + try { + restApiRequestBuilder.deleteViaRest("/deleteDependcyRoleRecord/" + id, true, null, null, requestedLoginId); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "deleteDependcyRoleRecord Failed", e); + } + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java index 2e780998..eab20f56 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/RoleServiceImpl.java @@ -33,10 +33,8 @@ import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.RoleFunction; import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("roleService") @Transactional public class RoleServiceImpl implements RoleService { @@ -57,13 +55,13 @@ public class RoleServiceImpl implements RoleService { } @SuppressWarnings("unchecked") - public List getRoleFunctions() { + public List getRoleFunctions(String loginId) { // List msgDB = getDataAccessService().getList(Profile.class, null); return getDataAccessService().getList(RoleFunction.class, null); } @SuppressWarnings("unchecked") - public List getAvailableChildRoles(Long roleId) { + public List getAvailableChildRoles(String loginId,Long roleId) { List availableChildRoles = (List) getDataAccessService().getList(Role.class, null); if (roleId == null || roleId == 0) { return availableChildRoles; @@ -71,7 +69,7 @@ public class RoleServiceImpl implements RoleService { Role currentRole = (Role) getDataAccessService().getDomainObject(Role.class, roleId, null); Set allParentRoles = new TreeSet(); - allParentRoles = getAllParentRolesAsList(currentRole, allParentRoles); + allParentRoles = getAllParentRolesAsList(loginId,currentRole, allParentRoles); Iterator availableChildRolesIterator = availableChildRoles.iterator(); while (availableChildRolesIterator.hasNext()) { @@ -84,48 +82,48 @@ public class RoleServiceImpl implements RoleService { } @SuppressWarnings("unchecked") - private Set getAllParentRolesAsList(Role role, Set allParentRoles) { + private Set getAllParentRolesAsList(String loginId,Role role, Set allParentRoles) { Set parentRoles = role.getParentRoles(); allParentRoles.addAll(parentRoles); Iterator parentRolesIterator = parentRoles.iterator(); while (parentRolesIterator.hasNext()) { - getAllParentRolesAsList(parentRolesIterator.next(), allParentRoles); + getAllParentRolesAsList( loginId,parentRolesIterator.next(), allParentRoles); } return allParentRoles; } - public RoleFunction getRoleFunction(String code) { + public RoleFunction getRoleFunction(String loginId,String code) { return (RoleFunction) getDataAccessService().getDomainObject(RoleFunction.class, code, null); } - public void saveRoleFunction(RoleFunction domainRoleFunction) { + public void saveRoleFunction(String loginId,RoleFunction domainRoleFunction) { getDataAccessService().saveDomainObject(domainRoleFunction, null); } - public void deleteRoleFunction(RoleFunction domainRoleFunction) { + public void deleteRoleFunction(String loginId,RoleFunction domainRoleFunction) { getDataAccessService().deleteDomainObject(domainRoleFunction, null); } - public Role getRole(Long id) { + public Role getRole(String loginId,Long id) { return (Role) getDataAccessService().getDomainObject(Role.class, id, null); } - public void saveRole(Role domainRole) { + public void saveRole(String loginId,Role domainRole) { getDataAccessService().saveDomainObject(domainRole, null); } - public void deleteRole(Role domainRole) { + public void deleteRole(String loginId,Role domainRole) { getDataAccessService().deleteDomainObject(domainRole, null); } @SuppressWarnings("unchecked") - public List getAvailableRoles() { + public List getAvailableRoles(String loginId) { return getDataAccessService().getList(Role.class, null); } @SuppressWarnings("unchecked") @Override - public List getActiveRoles() { + public List getActiveRoles(String loginId) { String filter = " where active_yn = 'Y' "; return getDataAccessService().getList(Role.class, filter, null, null); } @@ -139,7 +137,7 @@ public class RoleServiceImpl implements RoleService { } @Override - public void deleteDependcyRoleRecord(Long id) { + public void deleteDependcyRoleRecord(String loginId,Long id) { Connection conn = null; Statement stmt = null; try { diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java new file mode 100644 index 00000000..c0275b87 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessCentalizedImpl.java @@ -0,0 +1,77 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.openecomp.portalsdk.core.domain.RoleFunction; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.exception.SessionExpiredException; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.AppUtils; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +public class UrlAccessCentalizedImpl implements UrlAccessService { + + @Autowired + AppService appService; + + @Autowired + RoleService roleService; + + + @Override + public boolean isUrlAccessible(HttpServletRequest request, String currentUrl) { + + boolean isAccessible = false; + User user = UserUtils.getUserSession(request); + + + HttpSession session = AppUtils.getSession(request); + + if (session == null) { + throw new SessionExpiredException(); + } + + @SuppressWarnings("unchecked") + List allRoleFunctionsList = (List) session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTION_LIST)); + + List allUrls = new ArrayList(); + + for (int i = 0; i < allRoleFunctionsList.size(); i++) { + if (allRoleFunctionsList.get(i).getCode() != null && ((String) allRoleFunctionsList.get(i).getCode()).substring(0, 4).toUpperCase().equals("url_".toUpperCase())) { + String functionCd = ((String) allRoleFunctionsList.get(i).getCode()).substring(4).toUpperCase(); + allUrls.add(functionCd); + } + } + + @SuppressWarnings("unchecked") + Set roleFunction = UserUtils.getRoleFunctions(request); + List list = new ArrayList<>(roleFunction); + List UserURLlist = new ArrayList(); + + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i) != null && ((String) list.get(i)).substring(0, 4).toUpperCase().equals("url_".toUpperCase())) { + String functionCd = ((String) list.get(i)).substring(4).toUpperCase(); + UserURLlist.add(functionCd); + } + } + } + + if((!UserURLlist.contains(currentUrl) && !allUrls.contains(currentUrl)) || (UserURLlist.contains(currentUrl) && allUrls.contains(currentUrl))) + { + isAccessible = true; + }else { + isAccessible = false; + } + return isAccessible; + + } + + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java new file mode 100644 index 00000000..e01abfbb --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessImpl.java @@ -0,0 +1,48 @@ +package org.openecomp.portalsdk.core.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.domain.UrlsAccessible; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; + +public class UrlAccessImpl implements UrlAccessService{ + + @Autowired + DataAccessService dataAccessService; + + + + @Override + public boolean isUrlAccessible(HttpServletRequest request, String currentUrl) { + boolean isAccessible = false; + Map params = new HashMap<>(); + params.put("current_url", currentUrl); + List list = dataAccessService.executeNamedQuery("restrictedUrls", params, null); + + // loop through the list of restricted URL's + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + /* + * Object[] restrictedUrl = (Object[])list.get(i); + * + * String url = (String)restrictedUrl[0]; String functionCd = + * (String)restrictedUrl[1]; + */ + UrlsAccessible urlFunctions = (UrlsAccessible) list.get(i); + // String url = (String) urlFunctions.getUrl(); + String functionCd = (String) urlFunctions.getFunctionCd(); + if (UserUtils.isAccessible(request, functionCd)) { + isAccessible = true; + } + } + return isAccessible; + } + return true; + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java new file mode 100644 index 00000000..bb815f5d --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UrlAccessService.java @@ -0,0 +1,15 @@ +package org.openecomp.portalsdk.core.service; + +import javax.servlet.http.HttpServletRequest; + +public interface UrlAccessService { + + /** + * Answers whether the specified URL is accessible. + * + * @param request + * @param currentUrl + * @return true if yes, false if no. + */ + public boolean isUrlAccessible(HttpServletRequest request, String currentUrl); +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java new file mode 100644 index 00000000..3e7b2b14 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceCentalizedImpl.java @@ -0,0 +1,137 @@ +package org.openecomp.portalsdk.core.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.SortedSet; + +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.domain.support.CollaborateList; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; + + +@Transactional +public class UserProfileServiceCentalizedImpl implements UserProfileService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserProfileServiceCentalizedImpl.class); + + @Autowired + AppService appService; + + @Autowired + RestApiRequestBuilder restApiRequestBuilder; + + @Autowired + private DataAccessService dataAccessService; + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + @Override + public List findAll() { + List roles = new ArrayList<>(); + ObjectMapper mapper = new ObjectMapper(); + + String user = restApiRequestBuilder.getViaREST("/findAll", true,null); + try { + roles = mapper.readValue(user, + TypeFactory.defaultInstance().constructCollectionType(List.class, User.class)); + } catch (JsonParseException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json parsing failed", e); + } catch (JsonMappingException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json mapping failed", e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "IO exception", e); + } + + return roles; + } + + @Override + public User getUser(String id) { + ObjectMapper mapper = new ObjectMapper(); + User user = new User(); + String responseString = restApiRequestBuilder.getViaREST("/getUser/" + id, true,id); + try { + + user = mapper.readValue(responseString, User.class); + } catch (JsonParseException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json parsing failed", e); + } catch (JsonMappingException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Json mapping failed", e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "IO exception", e); + } + + return user; + } + + @Override + public User getUserByLoginId(String loginId) { + return getUser(loginId); + } + + @Override + public void saveUser(User user) { + try { + getDataAccessService().saveDomainObject(user, null); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveUser Failed", e); + } + } + + @Override + public List findAllUserWithOnOffline(String originOrgUserId) { + HashSet onlineUser = CollaborateList.getInstance().getAllUserName(); + List users = findAll(); + for (User u : users) { + if (onlineUser.contains(u.getOrgUserId())) + u.setOnline(true); + if (u.getOrgUserId() != null) { + if (originOrgUserId.compareTo(u.getOrgUserId()) > 0) { + u.setChatId(originOrgUserId + "-" + u.getOrgUserId()); + } else + u.setChatId(u.getOrgUserId() + "-" + originOrgUserId); + } + } + return users; + } + + @Override + public List findAllActive() { + List users = findAll(); + Iterator itr = users.iterator(); + while (itr.hasNext()) { + User u = (User) itr.next(); + if (!u.getActive()) + itr.remove();// if not active remove user from list + else { + SortedSet roles = u.getRoles(); + Iterator itrRoles = roles.iterator(); + while (itrRoles.hasNext()) { + Role role = (Role) itrRoles.next(); + if (!role.getActive()) + u.removeRole(role.getId());// if not active remove role + // from list + } + } + } + return users; + } + +} diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java index 2d134725..866318c5 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/openecomp/portalsdk/core/service/UserProfileServiceImpl.java @@ -31,10 +31,8 @@ import org.openecomp.portalsdk.core.domain.Role; import org.openecomp.portalsdk.core.domain.User; import org.openecomp.portalsdk.core.domain.support.CollaborateList; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service("userProfileService") @Transactional public class UserProfileServiceImpl implements UserProfileService{ @@ -42,6 +40,7 @@ public class UserProfileServiceImpl implements UserProfileService{ @Autowired private DataAccessService dataAccessService; + @SuppressWarnings("unchecked") public List findAll() { return getDataAccessService().getList(User.class, null); } @@ -94,6 +93,7 @@ public class UserProfileServiceImpl implements UserProfileService{ } public List findAllActive() { + @SuppressWarnings("unchecked") List users = getDataAccessService().getList(User.class, null); Iterator itr = users.iterator(); while(itr.hasNext()){ -- cgit 1.2.3-korg