XUserMgr extends XUserMgrBase { @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public VXUser createServiceConfigUser(String userName){ if (userName == null || "null".equalsIgnoreCase(userName) || userName.trim().isEmpty()) { logger.error("User Name: "+userName); throw restErrorUtil.createRESTException("Please provide a valid username.",MessageEnums.INVALID_INPUT_DATA); } VXUser vXUser = null; VXPortalUser vXPortalUser=null; XXUser xxUser = daoManager.getXXUser().findByUserName(userName); XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(userName); String actualPassword = ""; if(xxUser!=null){ vXUser = xUserService.populateViewBean(xxUser); return vXUser; } if(xxUser==null){ vXUser=new VXUser(); vXUser.setName(userName); vXUser.setUserSource(RangerCommonEnums.USER_EXTERNAL); vXUser.setDescription(vXUser.getName()); actualPassword = vXUser.getPassword(); } if(xXPortalUser==null){ vXPortalUser=new VXPortalUser(); vXPortalUser.setLoginId(userName); vXPortalUser.setEmailAddress(vXUser.getEmailAddress()); vXPortalUser.setFirstName(vXUser.getFirstName()); vXPortalUser.setLastName(vXUser.getLastName()); vXPortalUser.setPassword(vXUser.getPassword()); vXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL); ArrayList<String> roleList = new ArrayList<String>(); roleList.add(RangerConstants.ROLE_USER); vXPortalUser.setUserRoleList(roleList); xXPortalUser = userMgr.mapVXPortalUserToXXPortalUser(vXPortalUser); xXPortalUser=userMgr.createUser(xXPortalUser, RangerCommonEnums.STATUS_ENABLED, roleList); } VXUser createdXUser=null; if (xxUser == null && vXUser != null) { try { createdXUser = xUserService.createResource(vXUser); } catch (Exception ex) { logger.error("Error creating user: " + vXUser.getName(), ex); } } if(createdXUser!=null){ try{ logger.info("User created: "+createdXUser.getName()); createdXUser.setPassword(actualPassword); List<XXTrxLog> trxLogList = xUserService.getTransactionLog(createdXUser, "create"); String hiddenPassword = PropertiesUtil.getProperty("ranger.password.hidden", "*****"); createdXUser.setPassword(hiddenPassword); xaBizUtil.createTrxLog(trxLogList); if(xXPortalUser!=null){ vXPortalUser=userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount(xXPortalUser); assignPermissionToUser(vXPortalUser, true); } }catch(Exception ex){ logger.error("Error while assigning permissions to user: "+createdXUser.getName(),ex); } }else{ xxUser = daoManager.getXXUser().findByUserName(userName); if(xxUser!=null){ createdXUser = xUserService.populateViewBean(xxUser); } } 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 test49createServiceConfigUser() { XXUserDao xxUserDao = Mockito.mock(XXUserDao.class); XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class); XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class); VXUser vxUser = vxUser(); XXUser xXUser = xxUser(vxUser); VXPortalUser userProfile = userProfile(); XXPortalUser xXPortalUser = xxPortalUser(userProfile); Collection<String> userRoleList =getRoleList(); VXUserPermission vXUserPermission=vxUserPermission(); XXUserPermission xUserPermissionObj = xxUserPermission(); xUserPermissionObj.setModuleId(vXUserPermission.getModuleId()); xUserPermissionObj.setUserId(vXUserPermission.getUserId()); List<XXModuleDef> xXModuleDefs = xxModuleDefs(); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(xXUser); Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao); Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(xXPortalUser); Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vxUser); VXUser serviceConfigUser=xUserMgr.createServiceConfigUser(vxUser.getName()); Assert.assertNotNull(serviceConfigUser); Assert.assertEquals(xXUser.getName(), serviceConfigUser.getName()); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(null); Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao); Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(null); Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(null); Mockito.when(userMgr.mapVXPortalUserToXXPortalUser((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser); Mockito.when(userMgr.createUser(xXPortalUser,RangerCommonEnums.STATUS_ENABLED,userRoleList)).thenReturn(xXPortalUser); Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(vxUser); Mockito.when(userMgr.mapXXPortalUserToVXPortalUserForDefaultAccount((XXPortalUser) Mockito.any())).thenReturn(userProfile); Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao); Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); UserSessionBase userSession = Mockito.mock(UserSessionBase.class); Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>(); userSessions.add(userSession); serviceConfigUser=xUserMgr.createServiceConfigUser(vxUser.getName()); Assert.assertNotNull(serviceConfigUser); Assert.assertEquals(xXUser.getName(), serviceConfigUser.getName()); }
@Test public void test50createServiceConfigUser_WithBlankName() { destroySession(); Mockito.when(restErrorUtil.createRESTException("Please provide a valid username.",MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); xUserMgr.createServiceConfigUser(null); }
@Test public void test99createServiceConfigUser() { XXUserDao xxUserDao = Mockito.mock(XXUserDao.class); XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class); VXUser vxUser = vxUser(); XXUser xXUser = xxUser(vxUser); VXPortalUser userProfile = userProfile(); XXPortalUser xXPortalUser = xxPortalUser(userProfile); Collection<String> userRoleList =getRoleList(); VXUserPermission vXUserPermission=vxUserPermission(); XXUserPermission xUserPermissionObj = xxUserPermission(); xUserPermissionObj.setModuleId(vXUserPermission.getModuleId()); xUserPermissionObj.setUserId(vXUserPermission.getUserId()); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(xXUser); Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao); Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(xXPortalUser); Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vxUser); VXUser serviceConfigUser=xUserMgr.createServiceConfigUser(vxUser.getName()); Assert.assertNotNull(serviceConfigUser); Assert.assertEquals(xXUser.getName(), serviceConfigUser.getName()); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByUserName(vxUser.getName())).thenReturn(null); Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao); Mockito.when(userDao.findByLoginId(vxUser.getName())).thenReturn(null); Mockito.when(userMgr.mapVXPortalUserToXXPortalUser((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser); Mockito.when(userMgr.createUser(xXPortalUser,RangerCommonEnums.STATUS_ENABLED,userRoleList)).thenReturn(xXPortalUser); Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(null); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); UserSessionBase userSession = Mockito.mock(UserSessionBase.class); Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>(); userSessions.add(userSession); serviceConfigUser=xUserMgr.createServiceConfigUser(vxUser.getName()); Assert.assertNull(serviceConfigUser); }