use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test112CreateOrUpdateXUsers.
@Test
public void test112CreateOrUpdateXUsers() {
destroySession();
setup();
List<VXUser> vXUserList = new ArrayList<VXUser>();
VXUser vXUser = vxUser();
vXUser.setFirstName("testuser");
vXUser.setLastName("testuser");
vXUser.setPassword("TestPassword@123");
vXUser.setEmailAddress("");
vXUser.setUserSource(RangerCommonEnums.USER_APP);
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add(RangerConstants.ROLE_USER);
userRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
userRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
userRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
userRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
vXUser.setUserRoleList(userRoleList);
vXUserList.add(vXUser);
VXUserList users = new VXUserList(vXUserList);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setFirstName("testuser");
vXPortalUser.setLastName("testuser");
vXPortalUser.setPassword("TestPassword@123");
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
VXUserPermission userPermission = vxUserPermission();
List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
userPermList.add(userPermission);
xUserPermissionObj.setModuleId(userPermission.getModuleId());
xUserPermissionObj.setUserId(userPermission.getUserId());
xUserPermissionsList.add(xUserPermissionObj);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(vXUser);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
xUserMgr.createOrUpdateXUsers(users);
vXUser.setPassword("*****");
xUserMgr.createOrUpdateXUsers(users);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test42getUserRolesByExternalID.
@Test
public void test42getUserRolesByExternalID() {
destroySession();
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXUser vXUser = vxUser();
VXPortalUser userProfile = userProfile();
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.add(XXPortalUserRole);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermissionObj = xxUserPermission();
xUserPermissionsList.add(xUserPermissionObj);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xGroupPermissionList.add(xGroupPermissionObj);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = vxGroupPermission();
groupPermList.add(groupPermission);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(userId)).thenReturn(xPortalUserRoleList);
Mockito.when(xUserMgr.getXUser(userId)).thenReturn(vXUser);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(userProfile);
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
VXStringList vXStringList = xUserMgr.getUserRolesByExternalID(userId);
Assert.assertNotNull(vXStringList);
Mockito.when(restErrorUtil.createRESTException("Please provide a valid ID", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
Mockito.when(xUserService.readResourceWithOutLogin((Long) Mockito.any())).thenReturn(null);
xUserMgr.getUserRolesByExternalID(userId);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test03CreateXUser_WithBlankName.
@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);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test53getXGroupUserFromMap.
@Test
public void test53getXGroupUserFromMap() {
setup();
VXGroup vxGroup = vxGroup();
VXUser vxUser = vxUser();
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vxUser);
VXGroupUserInfo vxGUInfo = new VXGroupUserInfo();
vxGUInfo.setXgroupInfo(vxGroup);
vxGUInfo.setXuserInfo(vXUserList);
XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
XXGroup xxGroup = new XXGroup();
xxGroup.setId(vxGroup.getId());
xxGroup.setName(vxGroup.getName());
xxGroup.setDescription(vxGroup.getDescription());
xxGroup.setIsVisible(vxGroup.getIsVisible());
VXPortalUser userProfile = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(userProfile);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
VXGroupUserList vxGroupUserList = new VXGroupUserList();
List<VXGroupUser> vXGroupUsers = new ArrayList<VXGroupUser>();
VXGroupUser vxGroupUser = vxGroupUser();
vXGroupUsers.add(vxGroupUser);
vxGroupUserList.setVXGroupUsers(vXGroupUsers);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_USER);
Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
SearchCriteria searchCriteria = createsearchCriteria();
searchCriteria.addParam("xGroupId", xxGroup.getId());
Mockito.when(xxGroupDao.findByGroupName("")).thenReturn(null);
VXGroupUserInfo vxGUInfoObjNull = xUserMgr.getXGroupUserFromMap("");
Assert.assertNull(vxGUInfoObjNull.getXgroupInfo());
Mockito.when(xxGroupDao.findByGroupName(Mockito.anyString())).thenReturn(xxGroup);
Mockito.when(xGroupService.populateViewBean(xxGroup)).thenReturn(vxGroup);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
XXUser xXUser = xxUser(vxUser);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.getById(userId)).thenReturn(xXUser);
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(xXUser.getName().trim())).thenReturn(xXPortalUser);
XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
vxGUInfoObjNull = xUserMgr.getXGroupUserFromMap(xxGroup.getName());
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestXUserMgr method test05UpdateXUser.
@Test
public void test05UpdateXUser() {
setup();
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
Collection<String> existingRoleList = new ArrayList<String>();
existingRoleList.add(RangerConstants.ROLE_USER);
Collection<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("user12");
vxUser.setLastName("test12");
Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setUserRoleList(existingRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(vXPortalUser);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
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);
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.getAll()).thenReturn(xXModuleDefs);
XXUser xXUser = xxUser(vxUser);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
VXGroupUserList vxGroupUserList = vxGroupUserList();
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
VXUserPermission vXUserPermission = vxUserPermission();
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(vXUserPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
VXUser dbvxUser = xUserMgr.updateXUser(vxUser);
Assert.assertNotNull(dbvxUser);
Assert.assertEquals(dbvxUser.getId(), vxUser.getId());
Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
Mockito.verify(xUserService).updateResource(vxUser);
groupIdList.clear();
groupIdList.add(9L);
vxUser.setGroupIdList(groupIdList);
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Mockito.when(xGroupUserService.getTransactionLog((VXGroupUser) Mockito.any(), Mockito.anyString())).thenReturn(trxLogList);
VXGroup vXGroup = vxGroup();
Mockito.when(xGroupService.readResource(Mockito.anyLong())).thenReturn(vXGroup);
VXGroupUser vXGroupUser = vxGroupUser();
Mockito.when(xGroupUserService.createResource((VXGroupUser) Mockito.any())).thenReturn(vXGroupUser);
dbvxUser = xUserMgr.updateXUser(vxUser);
Assert.assertNotNull(dbvxUser);
}
Aggregations