Search in sources :

Example 6 with XXSecurityZoneDao

use of org.apache.ranger.db.XXSecurityZoneDao 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);
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXSecurityZoneRefTagServiceDao(org.apache.ranger.db.XXSecurityZoneRefTagServiceDao) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) XXServiceDao(org.apache.ranger.db.XXServiceDao) RangerPolicyValidator(org.apache.ranger.plugin.model.validation.RangerPolicyValidator) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPluginInfoList(org.apache.ranger.view.RangerPluginInfoList) RangerServiceList(org.apache.ranger.view.RangerServiceList) ArrayList(java.util.ArrayList) List(java.util.List) RangerExportPolicyList(org.apache.ranger.view.RangerExportPolicyList) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) PList(org.apache.ranger.plugin.store.PList) RangerService(org.apache.ranger.plugin.model.RangerService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) FileInputStream(java.io.FileInputStream) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) XXSecurityZoneRefServiceDao(org.apache.ranger.db.XXSecurityZoneRefServiceDao) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) XXService(org.apache.ranger.entity.XXService) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with XXSecurityZoneDao

use of org.apache.ranger.db.XXSecurityZoneDao 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);
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXSecurityZoneRefTagServiceDao(org.apache.ranger.db.XXSecurityZoneRefTagServiceDao) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) XXServiceDao(org.apache.ranger.db.XXServiceDao) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPluginInfoList(org.apache.ranger.view.RangerPluginInfoList) RangerServiceList(org.apache.ranger.view.RangerServiceList) ArrayList(java.util.ArrayList) List(java.util.List) RangerExportPolicyList(org.apache.ranger.view.RangerExportPolicyList) RangerPolicyList(org.apache.ranger.view.RangerPolicyList) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) PList(org.apache.ranger.plugin.store.PList) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) FileInputStream(java.io.FileInputStream) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) XXSecurityZoneRefServiceDao(org.apache.ranger.db.XXSecurityZoneRefServiceDao) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) XXService(org.apache.ranger.entity.XXService) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with XXSecurityZoneDao

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

the class TestSecurityZoneDBStore method test6getSecurityZones.

@Test
public void test6getSecurityZones() throws Exception {
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.ZONE_NAME, "sz1");
    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);
    securityZoneDBStore.getSecurityZones(filter);
    Assert.assertNotNull(xxSecurityZone);
    Assert.assertNotNull(xxSecurityZones);
    Mockito.verify(daoManager).getXXSecurityZoneDao();
    Mockito.verify(securityZoneService).read(xxSecurityZone.getId());
    Mockito.verify(predicateUtil).applyFilter(copy, filter);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 9 with XXSecurityZoneDao

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

the class TestSecurityZoneDBStore method test8createSecurityZoneWithExistingName.

@Test
public void test8createSecurityZoneWithExistingName() throws Exception {
    XXSecurityZone xxSecurityZone = new XXSecurityZone();
    xxSecurityZone.setId(2L);
    RangerSecurityZone securityZone = new RangerSecurityZone();
    RangerSecurityZone createdSecurityZone = new RangerSecurityZone();
    createdSecurityZone.setId(2L);
    XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
    Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(xxSecurityZone);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any(MessageEnums.class))).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    securityZoneDBStore.createSecurityZone(securityZone);
    Mockito.verify(daoManager, times(1)).getXXSecurityZoneDao();
    Mockito.verify(xXSecurityZoneDao, times(1)).findByZoneName(securityZone.getName());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) WebApplicationException(javax.ws.rs.WebApplicationException) MessageEnums(org.apache.ranger.common.MessageEnums) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 10 with XXSecurityZoneDao

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

the class TestSecurityZoneDBStore method test10deleteSecurityZoneByWrongName.

@Test
public void test10deleteSecurityZoneByWrongName() throws Exception {
    XXSecurityZone xxSecurityZone = new XXSecurityZone();
    xxSecurityZone.setId(2L);
    RangerSecurityZone securityZone = new RangerSecurityZone();
    securityZone.setId(2L);
    securityZone.setName("sz1");
    XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
    Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(null);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    securityZoneDBStore.deleteSecurityZoneByName(securityZone.getName());
    Mockito.verify(xXSecurityZoneDao, times(1)).findByZoneName(xxSecurityZone.getName());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) WebApplicationException(javax.ws.rs.WebApplicationException) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Aggregations

XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)14 Test (org.junit.Test)14 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)12 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)12 ArrayList (java.util.ArrayList)9 WebApplicationException (javax.ws.rs.WebApplicationException)6 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)3 XXTrxLog (org.apache.ranger.entity.XXTrxLog)3 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 XXSecurityZoneRefServiceDao (org.apache.ranger.db.XXSecurityZoneRefServiceDao)2 XXSecurityZoneRefTagServiceDao (org.apache.ranger.db.XXSecurityZoneRefTagServiceDao)2