use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test48searchXGroups.
@Test
public void test48searchXGroups() {
setupUser();
VXGroup vXGroup = vxGroup();
VXGroupList vXGroupListSort = new VXGroupList();
List<VXGroup> vXGroups = new ArrayList<VXGroup>();
vXGroups.add(vXGroup);
vXGroupListSort.setVXGroups(vXGroups);
String groupName = vXGroup.getName();
SearchCriteria testSearchCriteria = createsearchCriteria();
testSearchCriteria.addParam("name", groupName);
Mockito.when(xGroupService.getGroupByGroupName(groupName)).thenReturn(vXGroup);
Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(vXGroupListSort);
VXGroupList vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
testSearchCriteria.addParam("isvisible", "true");
vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
Assert.assertNotNull(vXGroupList);
testSearchCriteria = createsearchCriteria();
testSearchCriteria.addParam("name", groupName);
testSearchCriteria.addParam("groupsource", 1L);
Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(vXGroupListSort);
vXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
Assert.assertNotNull(vXGroupList);
testSearchCriteria = createsearchCriteria();
testSearchCriteria.addParam("name", groupName);
testSearchCriteria.addParam("userid", userId);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_USER);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
Mockito.when(xUserService.getXUserByUserName(userLoginID)).thenReturn(loggedInUser);
Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(vXGroupListSort);
List<Long> groupIdList = new ArrayList<Long>();
groupIdList.add(2L);
XXGroupUserDao mockxxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(mockxxGroupUserDao);
Mockito.when(mockxxGroupUserDao.findGroupIdListByUserId(loggedInUser.getId())).thenReturn(groupIdList);
XXModuleDefDao modDef = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(modDef);
List<String> lstModule = new ArrayList<String>();
lstModule.add(RangerConstants.MODULE_USER_GROUPS);
Mockito.when(modDef.findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(lstModule);
xUserMgr.searchXGroups(testSearchCriteria);
}
use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test10UpdateXGroup.
@Test
public void test10UpdateXGroup() {
XXGroupDao xxGroupDao = Mockito.mock(XXGroupDao.class);
XXGroupUserDao xxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
List<XXGroupUser> grpUsers = new ArrayList<XXGroupUser>();
setup();
VXGroup vXGroup = vxGroup();
XXGroup xxGroup = new XXGroup();
xxGroup.setName(groupName);
Mockito.when(daoManager.getXXGroup()).thenReturn(xxGroupDao);
Mockito.when(xxGroupDao.getById(vXGroup.getId())).thenReturn(xxGroup);
Mockito.when(xGroupService.updateResource(vXGroup)).thenReturn(vXGroup);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xxGroupUserDao);
Mockito.when(xxGroupUserDao.findByGroupId(vXGroup.getId())).thenReturn(grpUsers);
VXGroup dbvxGroup = xUserMgr.updateXGroup(vXGroup);
Assert.assertNotNull(dbvxGroup);
userId = dbvxGroup.getId();
Assert.assertEquals(userId, dbvxGroup.getId());
Assert.assertEquals(vXGroup.getDescription(), dbvxGroup.getDescription());
Assert.assertEquals(vXGroup.getName(), dbvxGroup.getName());
Mockito.verify(daoManager).getXXGroup();
Mockito.verify(daoManager).getXXGroupUser();
Mockito.verify(xGroupService).updateResource(vXGroup);
Mockito.verify(xxGroupUserDao).findByGroupId(vXGroup.getId());
Mockito.when(restErrorUtil.createRESTException("group name updates are not allowed.", MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
vXGroup.setName("UnknownGroup");
xUserMgr.updateXGroup(vXGroup);
}
use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test21DeleteXUser.
@Test
public void test21DeleteXUser() {
setup();
boolean force = true;
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 = vxGroupUserList();
XXGroupUserDao xGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGroupUserDao);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
XXPermMapDao xXPermMapDao = Mockito.mock(XXPermMapDao.class);
Mockito.when(xPermMapService.searchXPermMaps((SearchCriteria) Mockito.any())).thenReturn(vXPermMapList);
Mockito.when(daoManager.getXXPermMap()).thenReturn(xXPermMapDao);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
Mockito.when(xAuditMapService.searchXAuditMaps((SearchCriteria) Mockito.any())).thenReturn(vXAuditMapList);
Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
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");
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
XXModuleDef xModuleDef = xxModuleDef();
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
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());
xXAuthSessions.add(xXAuthSession);
List<XXUserPermission> xXUserPermissions = new ArrayList<XXUserPermission>();
xXUserPermissions.add(xxUserPermission());
List<XXPortalUserRole> xXPortalUserRoles = new ArrayList<XXPortalUserRole>();
xXPortalUserRoles.add(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>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
Mockito.when(daoManager.getXXPolicy()).thenReturn(xXPolicyDao);
Mockito.when(xXPolicyDao.findByUserId(vXUser.getId())).thenReturn(xXPolicyList);
RangerPolicy rangerPolicy = rangerPolicy();
Mockito.when(policyService.getPopulatedViewObject(xXPolicy)).thenReturn(rangerPolicy);
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);
force = false;
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test106getErrorWhenRoleUserFetchAnotherUserGroupInfo.
@Test
public void test106getErrorWhenRoleUserFetchAnotherUserGroupInfo() {
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);
List<String> permissionList = new ArrayList<String>();
permissionList.add(RangerConstants.MODULE_USER_GROUPS);
List<Long> groupIdList = new ArrayList<Long>();
groupIdList.add(2L);
VXUser loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_USER);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
loggedInUser.setGroupIdList(groupIdList);
VXUser vxUser = vxUser();
List<String> userRole = new ArrayList<String>();
userRole.add(RangerConstants.ROLE_USER);
vxUser.setId(8L);
vxUser.setName("test3");
vxUser.setUserRoleList(userRole);
vxUser.setUserSource(RangerCommonEnums.USER_UNIX);
Mockito.when(xUserService.getXUserByUserName("testuser")).thenReturn(loggedInUser);
XXGroupUserDao mockxxGroupUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(mockxxGroupUserDao);
Mockito.when(mockxxGroupUserDao.findGroupIdListByUserId(loggedInUser.getId())).thenReturn(groupIdList);
Mockito.when(restErrorUtil.create403RESTException("Logged-In user is not allowed to access requested group data.")).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.getXGroup(5L);
}
use of org.apache.ranger.db.XXGroupUserDao in project ranger by apache.
the class TestXUserMgr method test34updateXGroupPermission.
@Test
public void test34updateXGroupPermission() {
setup();
VXGroupPermission vXGroupPermission = vxGroupPermission();
XXGroupUserDao xGrpUserDao = Mockito.mock(XXGroupUserDao.class);
Mockito.when(daoManager.getXXGroupUser()).thenReturn(xGrpUserDao);
Mockito.when(xGroupPermissionService.updateResource(vXGroupPermission)).thenReturn(vXGroupPermission);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
Mockito.when(sessionMgr.getActiveUserSessionsForXUserId(userId)).thenReturn(userSessions);
List<XXGroupUser> xXGroupUserList = new ArrayList<XXGroupUser>();
VXGroupUser vxGroupUser = vxGroupUser();
XXGroupUser xXGroupUser = new XXGroupUser();
xXGroupUser.setId(vxGroupUser.getId());
xXGroupUser.setName(vxGroupUser.getName());
xXGroupUser.setParentGroupId(vxGroupUser.getParentGroupId());
xXGroupUser.setUserId(vxGroupUser.getUserId());
xXGroupUserList.add(xXGroupUser);
Mockito.when(xGrpUserDao.findByGroupId(vXGroupPermission.getGroupId())).thenReturn(xXGroupUserList);
VXGroupPermission dbGroupPermission = xUserMgr.updateXGroupPermission(vXGroupPermission);
Assert.assertNotNull(dbGroupPermission);
Assert.assertEquals(dbGroupPermission, vXGroupPermission);
Assert.assertEquals(dbGroupPermission.getId(), vXGroupPermission.getId());
Assert.assertEquals(dbGroupPermission.getGroupName(), vXGroupPermission.getGroupName());
Assert.assertEquals(dbGroupPermission.getOwner(), vXGroupPermission.getOwner());
Assert.assertEquals(dbGroupPermission.getUpdatedBy(), vXGroupPermission.getUpdatedBy());
Assert.assertEquals(dbGroupPermission.getCreateDate(), vXGroupPermission.getCreateDate());
Assert.assertEquals(dbGroupPermission.getGroupId(), vXGroupPermission.getGroupId());
Assert.assertEquals(dbGroupPermission.getIsAllowed(), vXGroupPermission.getIsAllowed());
Assert.assertEquals(dbGroupPermission.getModuleId(), vXGroupPermission.getModuleId());
Assert.assertEquals(dbGroupPermission.getUpdateDate(), vXGroupPermission.getUpdateDate());
Mockito.verify(xGroupPermissionService).updateResource(vXGroupPermission);
}
Aggregations