use of org.apache.ranger.db.XXSecurityZoneRefTagServiceDao in project ranger by apache.
the class TestServiceREST method test49importPoliciesFromFileAllowingOverride.
@SuppressWarnings("unchecked")
@Test
public void test49importPoliciesFromFileAllowingOverride() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerPolicyValidator policyValidator = Mockito.mock(RangerPolicyValidator.class);
Map<String, RangerPolicy> policiesMap = new LinkedHashMap<String, RangerPolicy>();
RangerPolicy rangerPolicy = rangerPolicy();
RangerService service = rangerService();
XXService xService = xService();
policiesMap.put("Name", rangerPolicy);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXSecurityZoneRefServiceDao xSecZoneRefServiceDao = Mockito.mock(XXSecurityZoneRefServiceDao.class);
XXSecurityZoneRefTagServiceDao xSecZoneRefTagServiceDao = Mockito.mock(XXSecurityZoneRefTagServiceDao.class);
XXSecurityZoneRefService xSecZoneRefService = Mockito.mock(XXSecurityZoneRefService.class);
XXSecurityZoneRefTagService xSecZoneRefTagService = Mockito.mock(XXSecurityZoneRefTagService.class);
XXSecurityZoneDao xSecZoneDao = Mockito.mock(XXSecurityZoneDao.class);
XXSecurityZone xSecZone = Mockito.mock(XXSecurityZone.class);
List<XXSecurityZoneRefService> zoneServiceList = new ArrayList<>();
List<XXSecurityZoneRefTagService> zoneTagServiceList = new ArrayList<>();
zoneServiceList.add(xSecZoneRefService);
zoneTagServiceList.add(xSecZoneRefTagService);
Map<String, String> zoneMappingMap = new LinkedHashMap<String, String>();
zoneMappingMap.put("ZoneSource", "ZoneDestination");
String PARAM_SERVICE_TYPE = "serviceType";
String serviceTypeList = "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop";
request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
SearchFilter filter = new SearchFilter();
filter.setParam("serviceType", "value");
File jsonPolicyFile = new File(importPoliceTestFilePath);
InputStream uploadedInputStream = new FileInputStream(jsonPolicyFile);
FormDataContentDisposition fileDetail = FormDataContentDisposition.name("file").fileName(jsonPolicyFile.getName()).size(uploadedInputStream.toString().length()).build();
boolean isOverride = true;
InputStream zoneInputStream = IOUtils.toInputStream("ZoneSource=ZoneDestination", "UTF-8");
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(request.getParameter(PARAM_SERVICE_TYPE)).thenReturn(serviceTypeList);
Mockito.when(svcStore.createPolicyMap(Mockito.any(Map.class), Mockito.any(List.class), Mockito.anyString(), Mockito.any(Map.class), Mockito.any(List.class), Mockito.any(List.class), Mockito.any(RangerPolicy.class), Mockito.any(Map.class))).thenReturn(policiesMap);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(daoManager.getXXService().findByName("HDFS_1-1-20150316062453")).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef().getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(svcStore.getMapFromInputStream(zoneInputStream)).thenReturn(zoneMappingMap);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xSecZoneDao);
Mockito.when(xSecZoneDao.findByZoneName(Mockito.anyString())).thenReturn(xSecZone);
Mockito.when(daoManager.getXXSecurityZoneRefService()).thenReturn(xSecZoneRefServiceDao);
Mockito.when(xSecZoneRefServiceDao.findByServiceNameAndZoneId(Mockito.anyString(), Mockito.anyLong())).thenReturn(zoneServiceList);
Mockito.when(daoManager.getXXSecurityZoneRefTagService()).thenReturn(xSecZoneRefTagServiceDao);
Mockito.when(xSecZoneRefTagServiceDao.findByTagServiceNameAndZoneId(Mockito.anyString(), Mockito.anyLong())).thenReturn(zoneTagServiceList);
Mockito.when(svcStore.getServiceByName(Mockito.anyString())).thenReturn(service);
serviceREST.importPoliciesFromFile(request, null, zoneInputStream, uploadedInputStream, fileDetail, isOverride, "unzoneToZone");
Mockito.verify(svcStore).createPolicy(rangerPolicy);
}
use of org.apache.ranger.db.XXSecurityZoneRefTagServiceDao in project ranger by apache.
the class SecurityZoneRefUpdater method cleanupRefTables.
public Boolean cleanupRefTables(RangerSecurityZone rangerSecurityZone) {
final Long zoneId = rangerSecurityZone == null ? null : rangerSecurityZone.getId();
if (zoneId == null) {
return false;
}
XXSecurityZoneRefServiceDao xZoneServiceDao = daoMgr.getXXSecurityZoneRefService();
XXSecurityZoneRefTagServiceDao xZoneTagServiceDao = daoMgr.getXXSecurityZoneRefTagService();
XXSecurityZoneRefResourceDao xZoneResourceDao = daoMgr.getXXSecurityZoneRefResource();
XXSecurityZoneRefUserDao xZoneUserDao = daoMgr.getXXSecurityZoneRefUser();
XXSecurityZoneRefGroupDao xZoneGroupDao = daoMgr.getXXSecurityZoneRefGroup();
for (XXSecurityZoneRefService service : xZoneServiceDao.findByZoneId(zoneId)) {
xZoneServiceDao.remove(service);
}
for (XXSecurityZoneRefTagService service : xZoneTagServiceDao.findByZoneId(zoneId)) {
xZoneTagServiceDao.remove(service);
}
for (XXSecurityZoneRefResource resource : xZoneResourceDao.findByZoneId(zoneId)) {
xZoneResourceDao.remove(resource);
}
for (XXSecurityZoneRefUser user : xZoneUserDao.findByZoneId(zoneId)) {
xZoneUserDao.remove(user);
}
for (XXSecurityZoneRefGroup group : xZoneGroupDao.findByZoneId(zoneId)) {
xZoneGroupDao.remove(group);
}
return true;
}
use of org.apache.ranger.db.XXSecurityZoneRefTagServiceDao in project ranger by apache.
the class TestServiceREST method test50importPoliciesFromFileNotAllowingOverride.
@SuppressWarnings("unchecked")
@Test
public void test50importPoliciesFromFileNotAllowingOverride() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Map<String, RangerPolicy> policiesMap = new LinkedHashMap<String, RangerPolicy>();
RangerPolicy rangerPolicy = rangerPolicy();
XXService xService = xService();
policiesMap.put("Name", rangerPolicy);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXSecurityZoneRefServiceDao xSecZoneRefServiceDao = Mockito.mock(XXSecurityZoneRefServiceDao.class);
XXSecurityZoneRefTagServiceDao xSecZoneRefTagServiceDao = Mockito.mock(XXSecurityZoneRefTagServiceDao.class);
XXSecurityZoneRefService xSecZoneRefService = Mockito.mock(XXSecurityZoneRefService.class);
XXSecurityZoneRefTagService xSecZoneRefTagService = Mockito.mock(XXSecurityZoneRefTagService.class);
XXSecurityZoneDao xSecZoneDao = Mockito.mock(XXSecurityZoneDao.class);
XXSecurityZone xSecZone = Mockito.mock(XXSecurityZone.class);
List<XXSecurityZoneRefService> zoneServiceList = new ArrayList<>();
List<XXSecurityZoneRefTagService> zoneTagServiceList = new ArrayList<>();
zoneServiceList.add(xSecZoneRefService);
zoneTagServiceList.add(xSecZoneRefTagService);
Map<String, String> zoneMappingMap = new LinkedHashMap<String, String>();
zoneMappingMap.put("ZoneSource", "ZoneDestination");
String PARAM_SERVICE_TYPE = "serviceType";
String serviceTypeList = "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop";
request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
SearchFilter filter = new SearchFilter();
filter.setParam("serviceType", "value");
File jsonPolicyFile = new File(importPoliceTestFilePath);
InputStream uploadedInputStream = new FileInputStream(jsonPolicyFile);
FormDataContentDisposition fileDetail = FormDataContentDisposition.name("file").fileName(jsonPolicyFile.getName()).size(uploadedInputStream.toString().length()).build();
boolean isOverride = false;
InputStream zoneInputStream = IOUtils.toInputStream("ZoneSource=ZoneDestination", "UTF-8");
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(request.getParameter(PARAM_SERVICE_TYPE)).thenReturn(serviceTypeList);
Mockito.when(svcStore.createPolicyMap(Mockito.any(Map.class), Mockito.any(List.class), Mockito.anyString(), Mockito.any(Map.class), Mockito.any(List.class), Mockito.any(List.class), Mockito.any(RangerPolicy.class), Mockito.any(Map.class))).thenReturn(policiesMap);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(daoManager.getXXService().findByName("HDFS_1-1-20150316062453")).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef().getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(svcStore.getMapFromInputStream(zoneInputStream)).thenReturn(zoneMappingMap);
Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xSecZoneDao);
Mockito.when(xSecZoneDao.findByZoneName(Mockito.anyString())).thenReturn(xSecZone);
Mockito.when(daoManager.getXXSecurityZoneRefService()).thenReturn(xSecZoneRefServiceDao);
Mockito.when(xSecZoneRefServiceDao.findByServiceNameAndZoneId(Mockito.anyString(), Mockito.anyLong())).thenReturn(zoneServiceList);
Mockito.when(daoManager.getXXSecurityZoneRefTagService()).thenReturn(xSecZoneRefTagServiceDao);
Mockito.when(xSecZoneRefTagServiceDao.findByTagServiceNameAndZoneId(Mockito.anyString(), Mockito.anyLong())).thenReturn(zoneTagServiceList);
serviceREST.importPoliciesFromFile(request, null, zoneInputStream, uploadedInputStream, fileDetail, isOverride, "unzoneToUnZone");
Mockito.verify(svcStore).createPolicy(rangerPolicy);
}
Aggregations