Search in sources :

Example 11 with XXGroupUserDao

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);
}
Also used : XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) VXGroupList(org.apache.ranger.view.VXGroupList) ArrayList(java.util.ArrayList) VXLong(org.apache.ranger.view.VXLong) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) SearchCriteria(org.apache.ranger.common.SearchCriteria) Test(org.junit.Test)

Example 12 with XXGroupUserDao

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);
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXGroup(org.apache.ranger.entity.XXGroup) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXGroup(org.apache.ranger.view.VXGroup) XXGroupDao(org.apache.ranger.db.XXGroupDao) Test(org.junit.Test)

Example 13 with XXGroupUserDao

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);
}
Also used : XXRoleRefUser(org.apache.ranger.entity.XXRoleRefUser) XXUser(org.apache.ranger.entity.XXUser) VXGroupUserList(org.apache.ranger.view.VXGroupUserList) VXPermMap(org.apache.ranger.view.VXPermMap) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) XXPolicy(org.apache.ranger.entity.XXPolicy) XXAuthSessionDao(org.apache.ranger.db.XXAuthSessionDao) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXPermMapDao(org.apache.ranger.db.XXPermMapDao) VXAuditMap(org.apache.ranger.view.VXAuditMap) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXPermMapList(org.apache.ranger.view.VXPermMapList) XXRoleRefUserDao(org.apache.ranger.db.XXRoleRefUserDao) XXAuditMapDao(org.apache.ranger.db.XXAuditMapDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXAuditMapList(org.apache.ranger.view.VXAuditMapList) VXUser(org.apache.ranger.view.VXUser) XXAuthSession(org.apache.ranger.entity.XXAuthSession) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXPolicyDao(org.apache.ranger.db.XXPolicyDao) Test(org.junit.Test)

Example 14 with XXGroupUserDao

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);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXLong(org.apache.ranger.view.VXLong) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 15 with XXGroupUserDao

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);
}
Also used : XXGroupUser(org.apache.ranger.entity.XXGroupUser) XXGroupUserDao(org.apache.ranger.db.XXGroupUserDao) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) UserSessionBase(org.apache.ranger.common.UserSessionBase) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)15 XXGroupUser (org.apache.ranger.entity.XXGroupUser)8 UserSessionBase (org.apache.ranger.common.UserSessionBase)7 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)7 XXModuleDef (org.apache.ranger.entity.XXModuleDef)7 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)7 HashSet (java.util.HashSet)6 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)6 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)6 XXPermMapDao (org.apache.ranger.db.XXPermMapDao)6 XXPolicyDao (org.apache.ranger.db.XXPolicyDao)6 XXPolicy (org.apache.ranger.entity.XXPolicy)6 VXGroup (org.apache.ranger.view.VXGroup)6 VXGroupUser (org.apache.ranger.view.VXGroupUser)6 VXUser (org.apache.ranger.view.VXUser)6 XXGroupDao (org.apache.ranger.db.XXGroupDao)5 XXUserDao (org.apache.ranger.db.XXUserDao)5