@Test public void test24updateRoles() { setup(); Collection<String> rolesList = new ArrayList<String>(); rolesList.add("ROLE_USER"); rolesList.add("ROLE_SYS_ADMIN"); XXPortalUserRole XXPortalUserRole = new XXPortalUserRole(); XXPortalUserRole.setId(userId); XXPortalUserRole.setUserRole("ROLE_USER"); List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>(); list.add(XXPortalUserRole); XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class); Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao); Mockito.when(userDao.findByUserId(userId)).thenReturn(list); boolean isFound = userMgr.updateRoles(userId, rolesList); Assert.assertFalse(isFound); }
public boolean updateRoles(Long userId, Collection<String> rolesList) { boolean rolesUpdated = false; if (rolesList == null || rolesList.size() == 0) { return false; } List<String> stringRolesList = new ArrayList<String>(); for (String userRole : rolesList) { if(!VALID_ROLE_LIST.contains(userRole.toUpperCase())){ throw restErrorUtil.createRESTException("Invalid user role, please provide valid user role.",MessageEnums.INVALID_INPUT_DATA); } stringRolesList.add(userRole); } xUserMgr.checkAccessRoles(stringRolesList); rangerBizUtil.blockAuditorRoleUser(); List<XXPortalUserRole> gjUserRoles = daoManager.getXXPortalUserRole() .findByUserId(userId); for (XXPortalUserRole gjUserRole : gjUserRoles) { boolean found = false; for (String userRole : rolesList) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (deleteUserRole(userId, gjUserRole)) { rolesUpdated = true; } } } for (String userRole : rolesList) { boolean found = false; for (XXPortalUserRole gjUserRole : gjUserRoles) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (addUserRole(userId, userRole) != null) { rolesUpdated = true; } } } return rolesUpdated; }
UserMgr { public boolean updateRoles(Long userId, Collection<String> rolesList) { boolean rolesUpdated = false; if (rolesList == null || rolesList.size() == 0) { return false; } List<String> stringRolesList = new ArrayList<String>(); for (String userRole : rolesList) { if(!VALID_ROLE_LIST.contains(userRole.toUpperCase())){ throw restErrorUtil.createRESTException("Invalid user role, please provide valid user role.",MessageEnums.INVALID_INPUT_DATA); } stringRolesList.add(userRole); } xUserMgr.checkAccessRoles(stringRolesList); rangerBizUtil.blockAuditorRoleUser(); List<XXPortalUserRole> gjUserRoles = daoManager.getXXPortalUserRole() .findByUserId(userId); for (XXPortalUserRole gjUserRole : gjUserRoles) { boolean found = false; for (String userRole : rolesList) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (deleteUserRole(userId, gjUserRole)) { rolesUpdated = true; } } } for (String userRole : rolesList) { boolean found = false; for (XXPortalUserRole gjUserRole : gjUserRoles) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (addUserRole(userId, userRole) != null) { rolesUpdated = true; } } } return rolesUpdated; } }
UserMgr { public boolean updateRoles(Long userId, Collection<String> rolesList) { boolean rolesUpdated = false; if (rolesList == null || rolesList.size() == 0) { return false; } List<String> stringRolesList = new ArrayList<String>(); for (String userRole : rolesList) { if(!VALID_ROLE_LIST.contains(userRole.toUpperCase())){ throw restErrorUtil.createRESTException("Invalid user role, please provide valid user role.",MessageEnums.INVALID_INPUT_DATA); } stringRolesList.add(userRole); } xUserMgr.checkAccessRoles(stringRolesList); rangerBizUtil.blockAuditorRoleUser(); List<XXPortalUserRole> gjUserRoles = daoManager.getXXPortalUserRole() .findByUserId(userId); for (XXPortalUserRole gjUserRole : gjUserRoles) { boolean found = false; for (String userRole : rolesList) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (deleteUserRole(userId, gjUserRole)) { rolesUpdated = true; } } } for (String userRole : rolesList) { boolean found = false; for (XXPortalUserRole gjUserRole : gjUserRoles) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (addUserRole(userId, userRole) != null) { rolesUpdated = true; } } } return rolesUpdated; } UserMgr(); }
UserMgr { public boolean updateRoles(Long userId, Collection<String> rolesList) { boolean rolesUpdated = false; if (rolesList == null || rolesList.size() == 0) { return false; } List<String> stringRolesList = new ArrayList<String>(); for (String userRole : rolesList) { if(!VALID_ROLE_LIST.contains(userRole.toUpperCase())){ throw restErrorUtil.createRESTException("Invalid user role, please provide valid user role.",MessageEnums.INVALID_INPUT_DATA); } stringRolesList.add(userRole); } xUserMgr.checkAccessRoles(stringRolesList); rangerBizUtil.blockAuditorRoleUser(); List<XXPortalUserRole> gjUserRoles = daoManager.getXXPortalUserRole() .findByUserId(userId); for (XXPortalUserRole gjUserRole : gjUserRoles) { boolean found = false; for (String userRole : rolesList) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (deleteUserRole(userId, gjUserRole)) { rolesUpdated = true; } } } for (String userRole : rolesList) { boolean found = false; for (XXPortalUserRole gjUserRole : gjUserRoles) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (addUserRole(userId, userRole) != null) { rolesUpdated = true; } } } return rolesUpdated; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForUpdate(XXPortalUser gjUser); String encrypt(String loginId, String password); String encryptWithOlderAlgo(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword,boolean logAudits); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updateOldUserName(String userLoginId,String newUserName, String currentPassword); }
UserMgr { public boolean updateRoles(Long userId, Collection<String> rolesList) { boolean rolesUpdated = false; if (rolesList == null || rolesList.size() == 0) { return false; } List<String> stringRolesList = new ArrayList<String>(); for (String userRole : rolesList) { if(!VALID_ROLE_LIST.contains(userRole.toUpperCase())){ throw restErrorUtil.createRESTException("Invalid user role, please provide valid user role.",MessageEnums.INVALID_INPUT_DATA); } stringRolesList.add(userRole); } xUserMgr.checkAccessRoles(stringRolesList); rangerBizUtil.blockAuditorRoleUser(); List<XXPortalUserRole> gjUserRoles = daoManager.getXXPortalUserRole() .findByUserId(userId); for (XXPortalUserRole gjUserRole : gjUserRoles) { boolean found = false; for (String userRole : rolesList) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (deleteUserRole(userId, gjUserRole)) { rolesUpdated = true; } } } for (String userRole : rolesList) { boolean found = false; for (XXPortalUserRole gjUserRole : gjUserRoles) { if (gjUserRole.getUserRole().equalsIgnoreCase(userRole)) { found = true; break; } } if (!found) { if (addUserRole(userId, userRole) != null) { rolesUpdated = true; } } } return rolesUpdated; } UserMgr(); XXPortalUser createUser(VXPortalUser userProfile, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(XXPortalUser user, int userStatus,
			Collection<String> userRoleList); XXPortalUser createUser(VXPortalUser userProfile, int userStatus); XXPortalUser updateUser(VXPortalUser userProfile); boolean updateRoles(Long userId, Collection<String> rolesList); void setUserRoles(Long userId, List<VXString> vStringRolesList); VXResponse changePassword(VXPasswordChange pwdChange); VXPortalUser changeEmailAddress(XXPortalUser gjUser,
			VXPasswordChange changeEmail); VXPortalUser deactivateUser(XXPortalUser gjUser); VXPortalUser getUserProfile(Long id); VXPortalUser getUserProfileByLoginId(); VXPortalUser getUserProfileByLoginId(String loginId); XXPortalUser mapVXPortalUserToXXPortalUser(VXPortalUser userProfile); VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,
			Collection<String> userRoleList); VXPortalUser mapXXPortalUserVXPortalUser(XXPortalUser user); XXPortalUser findByEmailAddress(String emailId); XXPortalUser findByLoginId(String loginId); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) Collection<String> getRolesForUser(XXPortalUser user); VXPortalUserList searchUsers(SearchCriteria searchCriteria); boolean deleteUserRole(Long userId, String userRole); boolean deleteUserRole(Long userId, XXPortalUserRole gjUserRole); XXPortalUserRole addUserRole(Long userId, String userRole); void checkAccess(Long userId); void checkAccess(XXPortalUser gjUser); void checkAccessForUpdate(XXPortalUser gjUser); String encrypt(String loginId, String password); String encryptWithOlderAlgo(String loginId, String password); VXPortalUser createUser(VXPortalUser userProfile); VXPortalUser createDefaultAccountUser(VXPortalUser userProfile); boolean isUserInRole(Long userId, String role); XXPortalUser updateUserWithPass(VXPortalUser userProfile); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updatePasswordInSHA256(String userName,String userPassword,boolean logAudits); void checkAdminAccess(); Collection<String> getRolesByLoginId(String loginId); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) XXPortalUser updateOldUserName(String userLoginId,String newUserName, String currentPassword);  }