Search in sources :

Example 26 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test108RoleUserWillSearchOnlyHisOwnGroupDetails.

@Test
public void test108RoleUserWillSearchOnlyHisOwnGroupDetails() {
    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);
    SearchCriteria testSearchCriteria = createsearchCriteria();
    List<Long> groupIdList = new ArrayList<Long>();
    groupIdList.add(5L);
    VXGroup expectedVXGroup = new VXGroup();
    expectedVXGroup.setId(5L);
    expectedVXGroup.setName("testGroup");
    List<VXGroup> grpList = new ArrayList<VXGroup>();
    grpList.add(expectedVXGroup);
    VXGroupList expectedVXGroupList = new VXGroupList();
    expectedVXGroupList.setVXGroups(grpList);
    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);
    Mockito.when(xGroupService.searchXGroups(testSearchCriteria)).thenReturn(expectedVXGroupList);
    XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
    Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
    VXGroupList rcvVXGroupList = xUserMgr.searchXGroups(testSearchCriteria);
    Assert.assertNotNull(rcvVXGroupList);
    Assert.assertEquals(rcvVXGroupList.getList().get(0).getId(), expectedVXGroup.getId());
    Assert.assertEquals(rcvVXGroupList.getList().get(0).getName(), expectedVXGroup.getName());
}
Also used : VXGroupList(org.apache.ranger.view.VXGroupList) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) SearchCriteria(org.apache.ranger.common.SearchCriteria) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) VXLong(org.apache.ranger.view.VXLong) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 27 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao 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 28 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test105getUserDetailsOfItsOwn.

@Test
public void test105getUserDetailsOfItsOwn() {
    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);
    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_USER);
    vxUser.setId(8L);
    vxUser.setName("test3");
    vxUser.setUserRoleList(userRole);
    vxUser.setUserSource(RangerCommonEnums.USER_UNIX);
    Mockito.when(xUserService.readResourceWithOutLogin(8L)).thenReturn(vxUser);
    Mockito.when(xUserService.getXUserByUserName("testuser")).thenReturn(loggedInUser);
    XXModuleDefDao mockxxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(mockxxModuleDefDao);
    Mockito.when(mockxxModuleDefDao.findAccessibleModulesByUserId(8L, 8L)).thenReturn(permissionList);
    VXUser expectedVXUser = xUserMgr.getXUser(8L);
    Assert.assertNotNull(expectedVXUser);
    Assert.assertEquals(expectedVXUser.getName(), vxUser.getName());
    destroySession();
    Mockito.when(restErrorUtil.create403RESTException("Logged-In user is not allowed to access requested user data.")).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    xUserMgr.getXUser(8L);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 29 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test17GetXUserByUserName.

@Test
public void test17GetXUserByUserName() {
    setupUser();
    VXUser vxUser = vxUser();
    Mockito.when(xUserService.getXUserByUserName(vxUser.getName())).thenReturn(vxUser);
    XXModuleDefDao xxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xxModuleDefDao);
    VXUser dbVXUser = xUserMgr.getXUserByUserName(vxUser.getName());
    Assert.assertNotNull(dbVXUser);
    userId = dbVXUser.getId();
    Assert.assertEquals(userId, dbVXUser.getId());
    Assert.assertEquals(dbVXUser.getName(), vxUser.getName());
    Assert.assertEquals(dbVXUser.getOwner(), vxUser.getOwner());
    Mockito.verify(xUserService, Mockito.atLeast(2)).getXUserByUserName(vxUser.getName());
}
Also used : XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXUser(org.apache.ranger.view.VXUser) Test(org.junit.Test)

Example 30 with XXModuleDefDao

use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.

the class TestXUserMgr method test24createXModuleDefPermission.

@Test
public void test24createXModuleDefPermission() {
    VXModuleDef vXModuleDef = vxModuleDef();
    Mockito.when(xModuleDefService.createResource(vXModuleDef)).thenReturn(vXModuleDef);
    XXModuleDefDao obj = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(obj);
    VXModuleDef dbMuduleDef = xUserMgr.createXModuleDefPermission(vXModuleDef);
    Assert.assertNotNull(dbMuduleDef);
    Assert.assertEquals(dbMuduleDef, vXModuleDef);
    Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
    Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
    Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
    Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
    Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
    Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
    Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
    Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
    Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
    Mockito.verify(xModuleDefService).createResource(vXModuleDef);
}
Also used : VXModuleDef(org.apache.ranger.view.VXModuleDef) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) Test(org.junit.Test)

Aggregations

XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)42 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)37 VXString (org.apache.ranger.view.VXString)33 XXUserPermission (org.apache.ranger.entity.XXUserPermission)27 XXModuleDef (org.apache.ranger.entity.XXModuleDef)26 VXPortalUser (org.apache.ranger.view.VXPortalUser)26 VXUser (org.apache.ranger.view.VXUser)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)22 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)21 XXPortalUser (org.apache.ranger.entity.XXPortalUser)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)18 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)18 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)16 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)15 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)15 Date (java.util.Date)14 UserSessionBase (org.apache.ranger.common.UserSessionBase)14 HashSet (java.util.HashSet)12 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)12