use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test94DeleteXUser.
@Test
public void test94DeleteXUser() {
setup();
boolean force = false;
VXUser vXUser = vxUser();
XXUser xXUser = new XXUser();
XXUserDao xXUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xXUserDao);
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
VXGroupUserList vxGroupUserList = new VXGroupUserList();
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
VXPortalUser vXPortalUser = userProfile();
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
Mockito.when(xXPortalUserDao.findByLoginId(vXUser.getName().trim())).thenReturn(xXPortalUser);
Mockito.when(xPortalUserService.populateViewBean(xXPortalUser)).thenReturn(vXPortalUser);
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
XXAuthSessionDao xXAuthSessionDao = Mockito.mock(XXAuthSessionDao.class);
XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXPortalUserRoleDao xXPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
Mockito.when(daoManager.getXXAuthSession()).thenReturn(xXAuthSessionDao);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
List<XXAuthSession> xXAuthSessions = new ArrayList<XXAuthSession>();
XXAuthSession xXAuthSession = new XXAuthSession();
xXAuthSession.setId(userId);
xXAuthSession.setLoginId(vXPortalUser.getLoginId());
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
XXPolicyDao xXPolicyDao = Mockito.mock(XXPolicyDao.class);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
XXRoleRefUserDao roleRefUserDao = Mockito.mock(XXRoleRefUserDao.class);
Mockito.when(daoManager.getXXRoleRefUser()).thenReturn(roleRefUserDao);
Mockito.when(roleRefUserDao.findByUserId(userId)).thenReturn(roleRefUser);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(new VXGroupUserList());
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(xXPolicyList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXPolicyDao.findByUserId(userId)).thenReturn(new ArrayList<XXPolicy>());
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(new VXPermMapList());
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(new VXAuditMapList());
xXAuthSessions.add(xXAuthSession);
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(xXAuthSessions);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXAuthSessionDao.getAuthSessionByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXAuthSession>());
XXUserPermission xUserPermissionObj = xxUserPermission();
xXUserPermissions.add(xUserPermissionObj);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xXUserPermissions);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(new ArrayList<XXUserPermission>());
xXPortalUserRoles.add(XXPortalUserRole);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(xXPortalUserRoles);
xUserMgr.deleteXUser(vXUser.getId(), force);
Mockito.when(xXPortalUserRoleDao.findByUserId(vXPortalUser.getId())).thenReturn(new ArrayList<XXPortalUserRole>());
xUserMgr.deleteXUser(vXUser.getId(), force);
vXUser.setName("");
Mockito.when(xXUserDao.getById(vXUser.getId())).thenReturn(xXUser);
Mockito.when(xUserService.populateViewBean(xXUser)).thenReturn(vXUser);
thrown.expect(NullPointerException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test104getKeyAdminAuditorUserDetailsWithUserHavingUSER_ROLE.
@Test
public void test104getKeyAdminAuditorUserDetailsWithUserHavingUSER_ROLE() {
destroySession();
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(false);
XXPortalUser xXPortalUser = new XXPortalUser();
xXPortalUser.setLoginId(userLoginID);
xXPortalUser.setId(userId);
currentUserSession.setXXPortalUser(xXPortalUser);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_USER);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
VXUser vxUser = vxUser();
List<String> userRole = new ArrayList<String>();
userRole.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
vxUser.setId(5L);
vxUser.setName("test3");
vxUser.setUserRoleList(userRole);
vxUser.setUserSource(RangerCommonEnums.USER_UNIX);
Mockito.when(xUserService.readResourceWithOutLogin(5L)).thenReturn(vxUser);
Mockito.when(xUserService.getXUserByUserName("testuser")).thenReturn(loggedInUser);
Mockito.when(restErrorUtil.create403RESTException("Logged-In user is not allowed to access requested user data.")).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.getXUser(5L);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test72UpdateXUser.
@Test
public void test72UpdateXUser() {
destroySession();
setup();
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("null");
vxUser.setLastName("null");
vxUser.setPassword("*****");
Mockito.when(xUserService.updateResource(vxUser)).thenReturn(vxUser);
VXPortalUser oldUserProfile = userProfile();
oldUserProfile.setUserSource(RangerCommonEnums.USER_APP);
oldUserProfile.setPassword(vxUser.getPassword());
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setUserRoleList(existingRoleList);
Mockito.when(userMgr.getUserProfileByLoginId(vxUser.getName())).thenReturn(oldUserProfile);
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
Mockito.when(userMgr.updateUserWithPass((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
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);
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);
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);
vxUser.setPassword("TestUser@1234");
oldUserProfile.setPassword(vxUser.getPassword());
vxGroupUserList.setVXGroupUsers(null);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
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);
Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException("user " + vxUser.getName() + " does not exist.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
vxUser = xUserMgr.updateXUser(vxUser);
Assert.assertNull(vxUser);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test113CreateOrUpdateXUsers.
@Test
public void test113CreateOrUpdateXUsers() {
destroySession();
setup();
VXUser vXUser = vxUser();
vXUser.setFirstName("null");
vXUser.setLastName("null");
List<VXUser> vXUserList = new ArrayList<VXUser>();
vXUserList.add(vXUser);
VXUserList users = new VXUserList(vXUserList);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
XXUser xXUser = xxUser(vXUser);
VXPortalUser vXPortalUser = userProfile();
vXPortalUser.setFirstName("null");
vXPortalUser.setLastName("null");
XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
List<String> lstRole = new ArrayList<String>();
lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
List<XXModuleDef> xXModuleDefs = new ArrayList<XXModuleDef>();
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
Mockito.when(xUserService.updateResource(vXUser)).thenReturn(vXUser);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
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);
Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
xUserMgr.createOrUpdateXUsers(users);
vXUserList.clear();
vXUser.setUserSource(RangerCommonEnums.USER_APP);
vXUser.setFirstName("testuser");
vXUser.setLastName("testuser");
vXUser.setPassword("TestPassword@123");
vXUserList.add(vXUser);
users = new VXUserList(vXUserList);
vXPortalUser = userProfile();
vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
vXPortalUser.setFirstName("testuser");
vXPortalUser.setLastName("testuser");
vXPortalUser.setPassword("TestPassword@123");
vXPortalUser.setUserRoleList(lstRole);
Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
Mockito.when(userMgr.updateUserWithPass((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
xUserMgr.createOrUpdateXUsers(users);
vXUser.setPassword("*****");
xUserMgr.createOrUpdateXUsers(users);
}
use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.
the class TestXUserMgr method test98modifyUserActiveStatus.
@Test
public void test98modifyUserActiveStatus() {
VXUser vxUser = vxUser();
XXUser xXUser = xxUser(vxUser);
HashMap<Long, Integer> statusMap = new HashMap<Long, Integer>();
statusMap.put(xXUser.getId(), 1);
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(true);
XXPortalUser xXPortalUser = new XXPortalUser();
xXPortalUser.setLoginId(null);
xXPortalUser.setId(userId);
currentUserSession.setXXPortalUser(xXPortalUser);
xUserMgr.modifyUserActiveStatus(statusMap);
}
Aggregations