XUserMgr extends XUserMgrBase { public void updateUserRolesPermissions(VXPortalUser oldUserProfile,List<String> roleListNewProfile){ Collection<String> roleListUpdatedProfile =new ArrayList<String>(); if (oldUserProfile != null && oldUserProfile.getId() != null) { Collection<String> roleListOldProfile = oldUserProfile.getUserRoleList(); if(roleListNewProfile!=null && roleListOldProfile!=null){ for (String role : roleListNewProfile) { if(role!=null && !roleListOldProfile.contains(role)){ roleListUpdatedProfile.add(role); } } } } if(roleListUpdatedProfile!=null && roleListUpdatedProfile.size()>0){ oldUserProfile.setUserRoleList(roleListUpdatedProfile); List<XXUserPermission> xuserPermissionList = daoManager .getXXUserPermission() .findByUserPermissionId(oldUserProfile.getId()); if (xuserPermissionList!=null && xuserPermissionList.size()>0){ for (XXUserPermission xXUserPermission : xuserPermissionList) { if (xXUserPermission != null) { xUserPermissionService.deleteResource(xXUserPermission.getId()); } } } assignPermissionToUser(oldUserProfile,true); if(roleListUpdatedProfile!=null && roleListUpdatedProfile.size()>0){ userMgr.updateRoles(oldUserProfile.getId(), oldUserProfile.getUserRoleList()); } } }  VXUser getXUserByUserName(String userName); VXGroup getGroupByGroupName(String groupName); VXUser createXUser(VXUser vXUser); void assignPermissionToUser(VXPortalUser vXPortalUser, boolean isCreate); void createOrUpdateUserPermisson(VXPortalUser portalUser, Long moduleId, boolean isCreate); HashMap<String, Long> getAllModuleNameAndIdMap(); VXUser updateXUser(VXUser vXUser); VXUserGroupInfo createXUserGroupFromMap(VXUserGroupInfo vXUserGroupInfo); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) VXGroupUserInfo createXGroupUserFromMap(
			VXGroupUserInfo vXGroupUserInfo); VXGroupUserInfo getXGroupUserFromMap(
			String groupName); VXUser createXUserWithOutLogin(VXUser vXUser); VXUser createExternalUser(String userName); VXGroup createXGroup(VXGroup vXGroup); VXGroup createXGroupWithoutLogin(VXGroup vXGroup); VXGroupUser createXGroupUser(VXGroupUser vXGroupUser); VXUser getXUser(Long id); VXGroupUser getXGroupUser(Long id); VXGroup getXGroup(Long id); void deleteXGroupAndXUser(String groupName, String userName); VXGroupList getXUserGroups(Long xUserId); Set<String> getGroupsForUser(String userName); VXUserList getXGroupUsers(SearchCriteria searchCriteria); @Override VXGroup updateXGroup(VXGroup vXGroup); VXGroupUser updateXGroupUser(VXGroupUser vXGroupUser); void deleteXGroupUser(Long id, boolean force); VXGroupGroup createXGroupGroup(VXGroupGroup vXGroupGroup); VXGroupGroup updateXGroupGroup(VXGroupGroup vXGroupGroup); void deleteXGroupGroup(Long id, boolean force); void deleteXPermMap(Long id, boolean force); VXLong getXPermMapSearchCount(SearchCriteria searchCriteria); void deleteXAuditMap(Long id, boolean force); VXLong getXAuditMapSearchCount(SearchCriteria searchCriteria); void modifyUserVisibility(HashMap<Long, Integer> visibilityMap); void modifyGroupsVisibility(HashMap<Long, Integer> groupVisibilityMap); VXModuleDef createXModuleDefPermission(VXModuleDef vXModuleDef); VXModuleDef getXModuleDefPermission(Long id); VXModuleDef updateXModuleDefPermission(VXModuleDef vXModuleDef); void deleteXModuleDefPermission(Long id, boolean force); VXUserPermission createXUserPermission(VXUserPermission vXUserPermission); VXUserPermission getXUserPermission(Long id); VXUserPermission updateXUserPermission(VXUserPermission vXUserPermission); void deleteXUserPermission(Long id, boolean force); VXGroupPermission createXGroupPermission(VXGroupPermission vXGroupPermission); VXGroupPermission getXGroupPermission(Long id); VXGroupPermission updateXGroupPermission(VXGroupPermission vXGroupPermission); void deleteXGroupPermission(Long id, boolean force); void modifyUserActiveStatus(HashMap<Long, Integer> statusMap); void checkAdminAccess(); void checkAccess(String loginID); VXPermMapList searchXPermMaps(SearchCriteria searchCriteria); VXAuditMapList searchXAuditMaps(SearchCriteria searchCriteria); void checkAccessRoles(List<String> stringRolesList); VXStringList setUserRolesByExternalID(Long userId, List<VXString> vStringRolesList); VXStringList setUserRolesByName(String userName, List<VXString> vStringRolesList); List<String> updateUserRoleAssignments(VXUsersGroupRoleAssignments ugRoleAssignments); VXStringList getUserRolesByExternalID(Long userId); VXStringList getUserRolesByName(String userName); void updateUserRolesPermissions(VXPortalUser oldUserProfile,List<String> roleListNewProfile); VXStringList getStringListFromUserRoleList(
			List<XXPortalUserRole> listXXPortalUserRole); boolean hasAccess(String loginID); VXUser getMaskedVXUser(VXUser vXUser); VXGroup getMaskedVXGroup(VXGroup vXGroup); @Override VXUserList searchXUsers(SearchCriteria searchCriteria); @Override VXGroupList searchXGroups(SearchCriteria searchCriteria); VXGroupList lookupXGroups(SearchCriteria searchCriteria); Collection<String> getMaskedCollection(Collection<String> listunMasked); boolean hasAccessToModule(String moduleName); void deleteXGroup(Long id, boolean force); synchronized void deleteXUser(Long id, boolean force); void restrictSelfAccountDeletion(String loginID); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) VXUser createServiceConfigUser(String userName); void denySelfRoleChange(String userName); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) synchronized VXUgsyncAuditInfo postUserGroupAuditInfo(
			VXUgsyncAuditInfo vxUgsyncAuditInfo); Long getUserStoreVersion(); Set<UserInfo> getUsers(); Set<GroupInfo> getGroups(); Map<String, Set<String>> getUserGroups(); RangerUserStore getRangerUserStore(Long lastKnownUserStoreVersion);  }
@Test public void test77updateUserRolesPermissions() { setup(); List<String> existingRoleList = new ArrayList<String>(); existingRoleList.add(RangerConstants.ROLE_USER); List<String> reqRoleList = new ArrayList<String>(); reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN); Collection<Long> groupIdList = new ArrayList<Long>(); groupIdList.add(userId); VXUser vxUser = vxUser(); vxUser.setUserRoleList(reqRoleList); vxUser.setUserSource(RangerCommonEnums.USER_EXTERNAL); vxUser.setGroupIdList(groupIdList); vxUser.setFirstName("null"); vxUser.setLastName("null"); vxUser.setPassword("*****"); VXPortalUser oldUserProfile = userProfile(); oldUserProfile.setUserSource(RangerCommonEnums.USER_APP); oldUserProfile.setPassword(vxUser.getPassword()); oldUserProfile.setUserRoleList(existingRoleList); VXPortalUser vXPortalUser = userProfile(); vXPortalUser.setUserRoleList(reqRoleList); List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>(); XXUserPermission xUserPermissionObj = new XXUserPermission(); xUserPermissionObj.setAddedByUserId(userId); xUserPermissionObj.setCreateTime(new Date()); xUserPermissionObj.setId(userId); xUserPermissionObj.setIsAllowed(1); xUserPermissionObj.setModuleId(1L); xUserPermissionObj.setUpdatedByUserId(userId); xUserPermissionObj.setUpdateTime(new Date()); xUserPermissionObj.setUserId(userId); xUserPermissionsList.add(xUserPermissionObj); UserSessionBase userSession = Mockito.mock(UserSessionBase.class); Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>(); userSessions.add(userSession); XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class); Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao); XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class); XXUserPermissionDao xXUserPermissionDao= Mockito.mock(XXUserPermissionDao.class); XXUserDao xxUserDao = Mockito.mock(XXUserDao.class); Collection<String> userRoleList = new ArrayList<String>(); userRoleList.add("ROLE_USER"); vXPortalUser.setUserRoleList(userRoleList); XXUser xXUser = xxUser(vxUser); List<XXModuleDef> xXModuleDefs = xxModuleDefs(); VXUserPermission userPermission = vxUserPermission(); List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>(); userPermList.add(userPermission); xUserPermissionObj.setModuleId(userPermission.getModuleId()); xUserPermissionObj.setUserId(userPermission.getUserId()); xUserPermissionsList.add(xUserPermissionObj); Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao); Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs); Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser); Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList); Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission); Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions); xUserMgr.updateUserRolesPermissions(oldUserProfile,reqRoleList); }