use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestXUserMgr method test125DeleteXUser.
@Test
public void test125DeleteXUser() {
destroySession();
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);
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
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");
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);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
XXSecurityZoneRefUser xZoneAdminUser = new XXSecurityZoneRefUser();
xZoneAdminUser.setZoneId(2L);
xZoneAdminUser.setUserId(userId);
xZoneAdminUser.setUserName(vXUser.getName());
xZoneAdminUser.setUserType(1);
List<XXSecurityZoneRefUser> zoneSecRefUser = new ArrayList<XXSecurityZoneRefUser>();
zoneSecRefUser.add(xZoneAdminUser);
XXSecurityZoneRefUserDao zoneSecRefUserDao = Mockito.mock(XXSecurityZoneRefUserDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefUser()).thenReturn(zoneSecRefUserDao);
Mockito.when(zoneSecRefUserDao.findByUserId(userId)).thenReturn(zoneSecRefUser);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getById(xZoneAdminUser.getZoneId())).thenReturn(xxSecurityZone);
List<XXRoleRefUser> roleRefUser = new ArrayList<XXRoleRefUser>();
XXRoleRefUser xRoleRefUser = new XXRoleRefUser();
xRoleRefUser.setRoleId(userId);
xRoleRefUser.setUserId(userId);
xRoleRefUser.setUserName(vXUser.getName().trim());
xRoleRefUser.setUserType(0);
roleRefUser.add(xRoleRefUser);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete User '" + vXUser.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXUser(vXUser.getId(), force);
force = false;
xUserMgr.deleteXUser(vXUser.getId(), force);
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestSecurityZoneDBStore method test7getSecurityZonesForService.
@Test
public void test7getSecurityZonesForService() throws Exception {
String serviceName = "hdfs_service";
Map<String, RangerSecurityZone.RangerSecurityZoneService> retMap = null;
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.ZONE_NAME, "sz1");
filter.setParam(SearchFilter.SERVICE_NAME, serviceName);
List<RangerSecurityZone> ret = new ArrayList<>();
List<XXSecurityZone> xxSecurityZones = new ArrayList<XXSecurityZone>();
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
xxSecurityZones.add(xxSecurityZone);
RangerSecurityZone rangerSecurityZone = new RangerSecurityZone();
rangerSecurityZone.setId(3L);
ret.add(rangerSecurityZone);
// List<RangerSecurityZone> copy = new ArrayList<>(ret);
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getAll()).thenReturn(xxSecurityZones);
Mockito.when(securityZoneService.read(xxSecurityZone.getId())).thenReturn(rangerSecurityZone);
// Mockito.doNothing().when(predicateUtil).applyFilter(copy, filter);
retMap = new HashMap<>();
retMap.put(rangerSecurityZone.getName(), rangerSecurityZone.getServices().get(serviceName));
securityZoneDBStore.getSecurityZonesForService(serviceName);
Assert.assertNotNull(xxSecurityZone);
Assert.assertNotNull(xxSecurityZones);
Mockito.verify(daoManager).getXXSecurityZoneDao();
Mockito.verify(securityZoneService).read(xxSecurityZone.getId());
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestSecurityZoneDBStore method test1createSecurityZone.
@Test
public void test1createSecurityZone() throws Exception {
XXSecurityZone xxSecurityZone = null;
RangerSecurityZone securityZone = new RangerSecurityZone();
RangerSecurityZone createdSecurityZone = new RangerSecurityZone();
createdSecurityZone.setId(2L);
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(xxSecurityZone);
Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
Mockito.when(securityZoneService.create(securityZone)).thenReturn(createdSecurityZone);
Mockito.doNothing().when(securityZoneRefUpdater).createNewZoneMappingForRefTable(createdSecurityZone);
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
RangerSecurityZone expectedSecurityZone = securityZoneDBStore.createSecurityZone(securityZone);
Assert.assertNull(xxSecurityZone);
Assert.assertEquals(createdSecurityZone.getId(), expectedSecurityZone.getId());
Mockito.verify(daoManager).getXXSecurityZoneDao();
Mockito.verify(daoManager).getXXGlobalState();
Mockito.verify(securityZoneService).create(securityZone);
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestSecurityZoneDBStore method test9updateSecurityZoneByUnknownId.
@Test
public void test9updateSecurityZoneByUnknownId() throws Exception {
RangerSecurityZone securityZoneToUpdate = new RangerSecurityZone();
securityZoneToUpdate.setId(2L);
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.findByZoneId(securityZoneToUpdate.getId())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
securityZoneDBStore.updateSecurityZoneById(securityZoneToUpdate);
Mockito.verify(daoManager, times(1)).getXXSecurityZoneDao();
Mockito.verify(xXSecurityZoneDao, times(1)).findByZoneId(securityZoneToUpdate.getId());
}
use of org.apache.ranger.db.XXSecurityZoneDao in project ranger by apache.
the class TestXUserMgr method test126DeleteXGroup.
@Test
public void test126DeleteXGroup() {
destroySession();
setup();
boolean force = true;
VXGroup vXGroup = vxGroup();
VXPermMapList vXPermMapList = new VXPermMapList();
VXPermMap vXPermMap1 = getVXPermMap();
List<VXPermMap> vXPermMaps = new ArrayList<VXPermMap>();
vXPermMaps.add(vXPermMap1);
vXPermMapList.setVXPermMaps(vXPermMaps);
VXAuditMapList vXAuditMapList = new VXAuditMapList();
List<VXAuditMap> vXAuditMaps = new ArrayList<VXAuditMap>();
VXAuditMap vXAuditMap = getVXAuditMap();
vXAuditMaps.add(vXAuditMap);
vXAuditMapList.setVXAuditMaps(vXAuditMaps);
List<XXGroupGroup> xXGroupGroups = new ArrayList<XXGroupGroup>();
XXGroupGroup xXGroupGroup = xxGroupGroup();
xXGroupGroups.add(xXGroupGroup);
List<XXGroupPermission> xXGroupPermissions = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = xxGroupPermission();
xXGroupPermissions.add(xGroupPermissionObj);
List<XXPolicy> xXPolicyList = new ArrayList<XXPolicy>();
XXPolicy xXPolicy = getXXPolicy();
xXPolicyList.add(xXPolicy);
List<XXResource> xResourceList = new ArrayList<XXResource>();
XXResource xXResource = new XXResource();
xXResource.setId(userId);
xXResource.setName("hadoopdev");
xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
xResourceList.add(xXResource);
XXSecurityZoneRefGroup xZoneAdminGroup = new XXSecurityZoneRefGroup();
xZoneAdminGroup.setZoneId(2L);
xZoneAdminGroup.setGroupId(vXGroup.getId());
xZoneAdminGroup.setGroupName(vXGroup.getName());
xZoneAdminGroup.setGroupType(1);
List<XXSecurityZoneRefGroup> zoneSecRefGroup = new ArrayList<XXSecurityZoneRefGroup>();
zoneSecRefGroup.add(xZoneAdminGroup);
XXSecurityZoneRefGroupDao zoneSecRefGroupDao = Mockito.mock(XXSecurityZoneRefGroupDao.class);
Mockito.when(daoManager.getXXSecurityZoneRefGroup()).thenReturn(zoneSecRefGroupDao);
Mockito.when(zoneSecRefGroupDao.findByGroupId(userId)).thenReturn(zoneSecRefGroup);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setId(2L);
securityZone.setName("sz1");
XXSecurityZone xxSecurityZone = new XXSecurityZone();
xxSecurityZone.setId(2L);
xxSecurityZone.setName("sz1");
XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
Mockito.when(xXSecurityZoneDao.getById(xZoneAdminGroup.getZoneId())).thenReturn(xxSecurityZone);
List<XXRoleRefGroup> roleRefGroup = new ArrayList<XXRoleRefGroup>();
XXRoleRefGroup xRoleRefGroup = new XXRoleRefGroup();
xRoleRefGroup.setRoleId(userId);
xRoleRefGroup.setGroupId(userId);
xRoleRefGroup.setGroupName(groupName);
xRoleRefGroup.setGroupType(0);
roleRefGroup.add(xRoleRefGroup);
XXRole xRole = new XXRole();
xRole.setId(userId);
xRole.setName("Role1");
VXResponse vXResponse = new VXResponse();
vXResponse.setStatusCode(HttpServletResponse.SC_BAD_REQUEST);
vXResponse.setMsgDesc("Can Not Delete Group '" + vXGroup.getName().trim() + "' as its present in " + RangerConstants.ROLE_FIELD);
Mockito.when(restErrorUtil.generateRESTException((VXResponse) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXGroup(vXGroup.getId(), force);
}
Aggregations