Search in sources :

Example 1 with XXSecurityZoneRefService

use of org.apache.ranger.entity.XXSecurityZoneRefService in project ranger by apache.

the class SecurityZoneRefUpdater method createNewZoneMappingForRefTable.

public void createNewZoneMappingForRefTable(RangerSecurityZone rangerSecurityZone) throws Exception {
    if (rangerSecurityZone == null) {
        return;
    }
    cleanupRefTables(rangerSecurityZone);
    final Long zoneId = rangerSecurityZone == null ? null : rangerSecurityZone.getId();
    final Map<String, RangerSecurityZoneService> zoneServices = rangerSecurityZone.getServices();
    final Set<String> adminUsers = new HashSet<>();
    final Set<String> adminUserGroups = new HashSet<>();
    final Set<String> auditUsers = new HashSet<>();
    final Set<String> auditUserGroups = new HashSet<>();
    final Set<String> tagServices = new HashSet<>();
    XXServiceDef xServiceDef = new XXServiceDef();
    adminUsers.addAll(rangerSecurityZone.getAdminUsers());
    adminUserGroups.addAll(rangerSecurityZone.getAdminUserGroups());
    auditUsers.addAll(rangerSecurityZone.getAuditUsers());
    auditUserGroups.addAll(rangerSecurityZone.getAuditUserGroups());
    tagServices.addAll(rangerSecurityZone.getTagServices());
    for (Map.Entry<String, RangerSecurityZoneService> service : zoneServices.entrySet()) {
        String serviceName = service.getKey();
        if (StringUtils.isBlank(serviceName)) {
            continue;
        }
        XXService xService = daoMgr.getXXService().findByName(serviceName);
        RangerService rService = svcService.getPopulatedViewObject(xService);
        xServiceDef = daoMgr.getXXServiceDef().findByName(rService.getType());
        XXSecurityZoneRefService xZoneService = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefService());
        xZoneService.setZoneId(zoneId);
        xZoneService.setServiceId(xService.getId());
        xZoneService.setServiceName(serviceName);
        daoMgr.getXXSecurityZoneRefService().create(xZoneService);
        for (Map<String, List<String>> resourceMap : service.getValue().getResources()) {
            // add all resourcedefs in pre defined set
            for (Map.Entry<String, List<String>> resource : resourceMap.entrySet()) {
                String resourceName = resource.getKey();
                if (StringUtils.isBlank(resourceName)) {
                    continue;
                }
                XXResourceDef xResourceDef = daoMgr.getXXResourceDef().findByNameAndServiceDefId(resourceName, xServiceDef.getId());
                XXSecurityZoneRefResource xZoneResource = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefResource());
                xZoneResource.setZoneId(zoneId);
                xZoneResource.setResourceDefId(xResourceDef.getId());
                xZoneResource.setResourceName(resourceName);
                daoMgr.getXXSecurityZoneRefResource().create(xZoneResource);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(tagServices)) {
        for (String tagService : tagServices) {
            if (StringUtils.isBlank(tagService)) {
                continue;
            }
            XXService xService = daoMgr.getXXService().findByName(tagService);
            if (xService == null || xService.getType() != RangerConstants.TAG_SERVICE_TYPE) {
                throw restErrorUtil.createRESTException("Tag Service named: " + tagService + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefTagService xZoneTagService = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefTagService());
            xZoneTagService.setZoneId(zoneId);
            xZoneTagService.setTagServiceId(xService.getId());
            xZoneTagService.setTagServiceName(xService.getName());
            daoMgr.getXXSecurityZoneRefTagService().create(xZoneTagService);
        }
    }
    if (CollectionUtils.isNotEmpty(adminUsers)) {
        for (String adminUser : adminUsers) {
            if (StringUtils.isBlank(adminUser)) {
                continue;
            }
            XXUser xUser = daoMgr.getXXUser().findByUserName(adminUser);
            if (xUser == null) {
                throw restErrorUtil.createRESTException("user with name: " + adminUser + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefUser xZoneAdminUser = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefUser());
            xZoneAdminUser.setZoneId(zoneId);
            xZoneAdminUser.setUserId(xUser.getId());
            xZoneAdminUser.setUserName(adminUser);
            xZoneAdminUser.setUserType(1);
            daoMgr.getXXSecurityZoneRefUser().create(xZoneAdminUser);
        }
    }
    if (CollectionUtils.isNotEmpty(adminUserGroups)) {
        for (String adminUserGroup : adminUserGroups) {
            if (StringUtils.isBlank(adminUserGroup)) {
                continue;
            }
            XXGroup xGroup = daoMgr.getXXGroup().findByGroupName(adminUserGroup);
            if (xGroup == null) {
                throw restErrorUtil.createRESTException("group with name: " + adminUserGroup + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefGroup xZoneAdminGroup = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefGroup());
            xZoneAdminGroup.setZoneId(zoneId);
            xZoneAdminGroup.setGroupId(xGroup.getId());
            xZoneAdminGroup.setGroupName(adminUserGroup);
            xZoneAdminGroup.setGroupType(1);
            daoMgr.getXXSecurityZoneRefGroup().create(xZoneAdminGroup);
        }
    }
    if (CollectionUtils.isNotEmpty(auditUsers)) {
        for (String auditUser : auditUsers) {
            if (StringUtils.isBlank(auditUser)) {
                continue;
            }
            XXUser xUser = daoMgr.getXXUser().findByUserName(auditUser);
            if (xUser == null) {
                throw restErrorUtil.createRESTException("user with name: " + auditUser + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefUser xZoneAuditUser = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefUser());
            xZoneAuditUser.setZoneId(zoneId);
            xZoneAuditUser.setUserId(xUser.getId());
            xZoneAuditUser.setUserName(auditUser);
            xZoneAuditUser.setUserType(0);
            daoMgr.getXXSecurityZoneRefUser().create(xZoneAuditUser);
        }
    }
    if (CollectionUtils.isNotEmpty(auditUserGroups)) {
        for (String auditUserGroup : auditUserGroups) {
            if (StringUtils.isBlank(auditUserGroup)) {
                continue;
            }
            XXGroup xGroup = daoMgr.getXXGroup().findByGroupName(auditUserGroup);
            if (xGroup == null) {
                throw restErrorUtil.createRESTException("group with name: " + auditUserGroup + " does not exist ", MessageEnums.INVALID_INPUT_DATA);
            }
            XXSecurityZoneRefGroup xZoneAuditGroup = rangerAuditFields.populateAuditFieldsForCreate(new XXSecurityZoneRefGroup());
            xZoneAuditGroup.setZoneId(zoneId);
            xZoneAuditGroup.setGroupId(xGroup.getId());
            xZoneAuditGroup.setGroupName(auditUserGroup);
            xZoneAuditGroup.setGroupType(0);
            daoMgr.getXXSecurityZoneRefGroup().create(xZoneAuditGroup);
        }
    }
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXUser(org.apache.ranger.entity.XXUser) XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) RangerSecurityZoneService(org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService) XXGroup(org.apache.ranger.entity.XXGroup) XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) List(java.util.List) RangerService(org.apache.ranger.plugin.model.RangerService) XXSecurityZoneRefResource(org.apache.ranger.entity.XXSecurityZoneRefResource) XXService(org.apache.ranger.entity.XXService) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with XXSecurityZoneRefService

use of org.apache.ranger.entity.XXSecurityZoneRefService in project ranger by apache.

the class ServiceREST method validateDestZoneServiceMapping.

private boolean validateDestZoneServiceMapping(String destinationZoneName, RangerPolicy policyInJson, Map<String, String> servicesMappingMap) {
    boolean isZoneServiceExistAtDestination = false;
    XXSecurityZone xdestZone = daoManager.getXXSecurityZoneDao().findByZoneName(destinationZoneName);
    if (xdestZone == null) {
        LOG.error("destination zone provided does not exist");
        throw restErrorUtil.createRESTException("destination zone provided does not exist");
    }
    // CHECK IF json policies service is there on destination and asscioated with
    // destination zone.
    String serviceNameToCheck = policyInJson.getService();
    if (StringUtils.isNotBlank(serviceNameToCheck) && servicesMappingMap.containsKey(serviceNameToCheck)) {
        serviceNameToCheck = servicesMappingMap.get(policyInJson.getService());
    }
    List<XXSecurityZoneRefService> serviceZoneMapping = daoManager.getXXSecurityZoneRefService().findByServiceNameAndZoneId(serviceNameToCheck, xdestZone.getId());
    List<XXSecurityZoneRefTagService> tagServiceZoneMapping = daoManager.getXXSecurityZoneRefTagService().findByTagServiceNameAndZoneId(serviceNameToCheck, xdestZone.getId());
    if (!CollectionUtils.isEmpty(serviceZoneMapping) || !CollectionUtils.isEmpty(tagServiceZoneMapping)) {
        isZoneServiceExistAtDestination = true;
    }
    return isZoneServiceExistAtDestination;
}
Also used : XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) VXString(org.apache.ranger.view.VXString) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService)

Example 3 with XXSecurityZoneRefService

use of org.apache.ranger.entity.XXSecurityZoneRefService 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 4 with XXSecurityZoneRefService

use of org.apache.ranger.entity.XXSecurityZoneRefService 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 5 with XXSecurityZoneRefService

use of org.apache.ranger.entity.XXSecurityZoneRefService 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;
}
Also used : XXSecurityZoneRefGroup(org.apache.ranger.entity.XXSecurityZoneRefGroup) XXSecurityZoneRefTagServiceDao(org.apache.ranger.db.XXSecurityZoneRefTagServiceDao) XXSecurityZoneRefResourceDao(org.apache.ranger.db.XXSecurityZoneRefResourceDao) XXSecurityZoneRefTagService(org.apache.ranger.entity.XXSecurityZoneRefTagService) XXSecurityZoneRefServiceDao(org.apache.ranger.db.XXSecurityZoneRefServiceDao) XXSecurityZoneRefUserDao(org.apache.ranger.db.XXSecurityZoneRefUserDao) XXSecurityZoneRefUser(org.apache.ranger.entity.XXSecurityZoneRefUser) XXSecurityZoneRefGroupDao(org.apache.ranger.db.XXSecurityZoneRefGroupDao) XXSecurityZoneRefResource(org.apache.ranger.entity.XXSecurityZoneRefResource) XXSecurityZoneRefService(org.apache.ranger.entity.XXSecurityZoneRefService)

Aggregations

XXSecurityZoneRefService (org.apache.ranger.entity.XXSecurityZoneRefService)5 XXSecurityZoneRefTagService (org.apache.ranger.entity.XXSecurityZoneRefTagService)5 List (java.util.List)3 Map (java.util.Map)3 XXSecurityZoneRefServiceDao (org.apache.ranger.db.XXSecurityZoneRefServiceDao)3 XXSecurityZoneRefTagServiceDao (org.apache.ranger.db.XXSecurityZoneRefTagServiceDao)3 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)3 XXService (org.apache.ranger.entity.XXService)3 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3 VXString (org.apache.ranger.view.VXString)3 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)2 XXServiceDao (org.apache.ranger.db.XXServiceDao)2