XUserMgr extends XUserMgrBase { public VXUser createXUser(VXUser vXUser) { checkAdminAccess(); xaBizUtil.blockAuditorRoleUser(); validatePassword(vXUser); String userName = vXUser.getName(); if (userName == null || "null".equalsIgnoreCase(userName) || userName.trim().isEmpty()) { throw restErrorUtil.createRESTException( "Please provide a valid username.", MessageEnums.INVALID_INPUT_DATA); } if (vXUser.getDescription() == null) { vXUser.setDescription(vXUser.getName()); } String actualPassword = vXUser.getPassword(); VXPortalUser vXPortalUser = new VXPortalUser(); vXPortalUser.setLoginId(userName); vXPortalUser.setFirstName(vXUser.getFirstName()); if("null".equalsIgnoreCase(vXPortalUser.getFirstName())){ vXPortalUser.setFirstName(""); } vXPortalUser.setLastName(vXUser.getLastName()); if("null".equalsIgnoreCase(vXPortalUser.getLastName())){ vXPortalUser.setLastName(""); } String emailAddress = vXUser.getEmailAddress(); if (StringUtils.isNotEmpty(emailAddress) && !stringUtil.validateEmail(emailAddress)) { logger.warn("Invalid email address:" + emailAddress); throw restErrorUtil.createRESTException("Please provide valid email address.", MessageEnums.INVALID_INPUT_DATA); } vXPortalUser.setEmailAddress(emailAddress); if (vXPortalUser.getFirstName() != null && vXPortalUser.getLastName() != null && !vXPortalUser.getFirstName().trim().isEmpty() && !vXPortalUser.getLastName().trim().isEmpty()) { vXPortalUser.setPublicScreenName(vXPortalUser.getFirstName() + " " + vXPortalUser.getLastName()); } else { vXPortalUser.setPublicScreenName(vXUser.getName()); } vXPortalUser.setPassword(actualPassword); vXPortalUser.setUserRoleList(vXUser.getUserRoleList()); vXPortalUser = userMgr.createDefaultAccountUser(vXPortalUser); VXUser createdXUser = xUserService.createResource(vXUser); createdXUser.setPassword(actualPassword); List<XXTrxLog> trxLogList = xUserService.getTransactionLog( createdXUser, "create"); String hiddenPassword = PropertiesUtil.getProperty("ranger.password.hidden", "*****"); createdXUser.setPassword(hiddenPassword); Collection<String> groupNamesList = new ArrayList<String>(); Collection<Long> groupIdList = vXUser.getGroupIdList(); List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>(); if (groupIdList != null) { for (Long groupId : groupIdList) { VXGroupUser vXGroupUser = createXGroupUser( createdXUser.getId(), groupId); vXGroupUsers.add(vXGroupUser); groupNamesList.add(vXGroupUser.getName()); } } createdXUser.setGroupIdList(groupIdList); createdXUser.setGroupNameList(groupNamesList); for (VXGroupUser vXGroupUser : vXGroupUsers) { trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, "create")); } xaBizUtil.createTrxLog(trxLogList); if(vXPortalUser!=null){ assignPermissionToUser(vXPortalUser, true); } return createdXUser; }  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 test02CreateXUser_WithBlankName() { setup(); VXUser vxUser = vxUser(); ArrayList<String> userRoleListVXPortaUser = getRoleList(); VXPortalUser vXPortalUser = new VXPortalUser(); vXPortalUser.setUserRoleList(userRoleListVXPortaUser); vxUser.setName(null); Mockito.when(restErrorUtil.createRESTException("Please provide a valid username.",MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); VXUser vXUser=xUserMgr.createXUser(vxUser); Assert.assertNull(vXUser); }
@Test public void test03CreateXUser_WithBlankName() { destroySession(); setup(); VXUser vxUser = vxUser(); ArrayList<String> userRoleListVXPortaUser = getRoleList(); VXPortalUser vXPortalUser = new VXPortalUser(); vXPortalUser.setUserRoleList(userRoleListVXPortaUser); vxUser.setName(""); Mockito.when(restErrorUtil.createRESTException("Please provide a valid username.",MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); xUserMgr.createXUser(vxUser); }
@Test public void test04CreateXUser_WithBlankValues() { setup(); VXUser vxUser = vxUser(); ArrayList<String> userRoleListVXPortaUser = getRoleList(); VXPortalUser vXPortalUser = new VXPortalUser(); vXPortalUser.setUserRoleList(userRoleListVXPortaUser); vxUser.setDescription(null); vxUser.setFirstName("null"); vxUser.setLastName("null"); Mockito.when(xUserService.createResource(vxUser)).thenReturn(vxUser); Mockito.when(stringUtil.validateEmail("test@test.com")).thenReturn(true); xUserMgr.createXUser(vxUser); }