Search in sources :

Example 1 with XXServiceResourceElement

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

the class TagDBStore method createResourceForServiceResource.

private void createResourceForServiceResource(Long resourceId, RangerServiceResource serviceResource) {
    String serviceName = serviceResource.getServiceName();
    XXService xService = daoManager.getXXService().findByName(serviceName);
    if (xService == null) {
        throw errorUtil.createRESTException("No Service found with name: " + serviceName, MessageEnums.ERROR_CREATING_OBJECT);
    }
    XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById(xService.getType());
    if (xServiceDef == null) {
        throw errorUtil.createRESTException("No Service-Def found with ID: " + xService.getType(), MessageEnums.ERROR_CREATING_OBJECT);
    }
    Map<String, RangerPolicy.RangerPolicyResource> resElements = serviceResource.getResourceElements();
    for (Map.Entry<String, RangerPolicyResource> resElement : resElements.entrySet()) {
        XXResourceDef xResDef = daoManager.getXXResourceDef().findByNameAndServiceDefId(resElement.getKey(), xServiceDef.getId());
        if (xResDef == null) {
            LOG.error("TagDBStore.createResource: ResourceType is not valid [" + resElement.getKey() + "]");
            throw errorUtil.createRESTException("Resource Type is not valid [" + resElement.getKey() + "]", MessageEnums.DATA_NOT_FOUND);
        }
        RangerPolicyResource policyRes = resElement.getValue();
        XXServiceResourceElement resourceElement = new XXServiceResourceElement();
        resourceElement.setIsExcludes(policyRes.getIsExcludes());
        resourceElement.setIsRecursive(policyRes.getIsRecursive());
        resourceElement.setResDefId(xResDef.getId());
        resourceElement.setResourceId(resourceId);
        resourceElement = rangerAuditFields.populateAuditFieldsForCreate(resourceElement);
        resourceElement = daoManager.getXXServiceResourceElement().create(resourceElement);
        int sortOrder = 1;
        for (String resVal : policyRes.getValues()) {
            XXServiceResourceElementValue resourceElementValue = new XXServiceResourceElementValue();
            resourceElementValue.setResElementId(resourceElement.getId());
            resourceElementValue.setValue(resVal);
            resourceElementValue.setSortOrder(sortOrder);
            resourceElementValue = rangerAuditFields.populateAuditFieldsForCreate(resourceElementValue);
            resourceElementValue = daoManager.getXXServiceResourceElementValue().create(resourceElementValue);
            sortOrder++;
        }
    }
}
Also used : XXServiceResourceElementValue(org.apache.ranger.entity.XXServiceResourceElementValue) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXService(org.apache.ranger.entity.XXService) HashMap(java.util.HashMap) XXTagResourceMap(org.apache.ranger.entity.XXTagResourceMap) Map(java.util.Map) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Example 2 with XXServiceResourceElement

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

the class TagDBStore method deleteAllTagObjectsForService.

@Override
public void deleteAllTagObjectsForService(String serviceName) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagDBStore.deleteAllTagObjectsForService(" + serviceName + ")");
    }
    XXService service = daoManager.getXXService().findByName(serviceName);
    if (service != null) {
        Long serviceId = service.getId();
        List<XXTagAttribute> xxTagAttributes = daoManager.getXXTagAttribute().findByServiceIdAndOwner(serviceId, RangerTag.OWNER_SERVICERESOURCE);
        List<XXTag> xxTags = daoManager.getXXTag().findByServiceIdAndOwner(serviceId, RangerTag.OWNER_SERVICERESOURCE);
        List<XXTagResourceMap> xxTagResourceMaps = daoManager.getXXTagResourceMap().findByServiceId(serviceId);
        if (CollectionUtils.isNotEmpty(xxTagResourceMaps)) {
            for (XXTagResourceMap xxTagResourceMap : xxTagResourceMaps) {
                try {
                    daoManager.getXXTagResourceMap().remove(xxTagResourceMap);
                } catch (Exception e) {
                    LOG.error("Error deleting RangerTagResourceMap with id=" + xxTagResourceMap.getId(), e);
                    throw e;
                }
            }
        }
        if (CollectionUtils.isNotEmpty(xxTagAttributes)) {
            for (XXTagAttribute xxTagAttribute : xxTagAttributes) {
                try {
                    daoManager.getXXTagAttribute().remove(xxTagAttribute);
                } catch (Exception e) {
                    LOG.error("Error deleting RangerTagAttribute with id=" + xxTagAttribute.getId(), e);
                    throw e;
                }
            }
        }
        if (CollectionUtils.isNotEmpty(xxTags)) {
            for (XXTag xxTag : xxTags) {
                try {
                    daoManager.getXXTag().remove(xxTag);
                } catch (Exception e) {
                    LOG.error("Error deleting RangerTag with id=" + xxTag.getId(), e);
                    throw e;
                }
            }
        }
        List<XXServiceResourceElementValue> xxServiceResourceElementValues = daoManager.getXXServiceResourceElementValue().findByServiceId(serviceId);
        if (CollectionUtils.isNotEmpty(xxServiceResourceElementValues)) {
            for (XXServiceResourceElementValue xxServiceResourceElementValue : xxServiceResourceElementValues) {
                try {
                    daoManager.getXXServiceResourceElementValue().remove(xxServiceResourceElementValue);
                } catch (Exception e) {
                    LOG.error("Error deleting ServiceResourceElementValue with id=" + xxServiceResourceElementValue.getId(), e);
                    throw e;
                }
            }
        }
        List<XXServiceResourceElement> xxServiceResourceElements = daoManager.getXXServiceResourceElement().findByServiceId(serviceId);
        if (CollectionUtils.isNotEmpty(xxServiceResourceElements)) {
            for (XXServiceResourceElement xxServiceResourceElement : xxServiceResourceElements) {
                try {
                    daoManager.getXXServiceResourceElement().remove(xxServiceResourceElement);
                } catch (Exception e) {
                    LOG.error("Error deleting ServiceResourceElement with id=" + xxServiceResourceElement.getId(), e);
                    throw e;
                }
            }
        }
        List<XXServiceResource> xxServiceResources = daoManager.getXXServiceResource().findByServiceId(serviceId);
        if (CollectionUtils.isNotEmpty(xxServiceResources)) {
            for (XXServiceResource xxServiceResource : xxServiceResources) {
                try {
                    daoManager.getXXServiceResource().remove(xxServiceResource);
                } catch (Exception e) {
                    LOG.error("Error deleting RangerServiceResource with id=" + xxServiceResource.getId(), e);
                    throw e;
                }
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagDBStore.deleteAllTagObjectsForService(" + serviceName + ")");
    }
}
Also used : XXTagResourceMap(org.apache.ranger.entity.XXTagResourceMap) XXServiceResource(org.apache.ranger.entity.XXServiceResource) RangerServiceNotFoundException(org.apache.ranger.plugin.util.RangerServiceNotFoundException) XXServiceResourceElementValue(org.apache.ranger.entity.XXServiceResourceElementValue) XXTag(org.apache.ranger.entity.XXTag) XXService(org.apache.ranger.entity.XXService) XXTagAttribute(org.apache.ranger.entity.XXTagAttribute) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Example 3 with XXServiceResourceElement

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

the class TagDBStore method deleteResourceForServiceResource.

private void deleteResourceForServiceResource(Long resourceId) {
    List<XXServiceResourceElement> resElements = daoManager.getXXServiceResourceElement().findByResourceId(resourceId);
    if (CollectionUtils.isNotEmpty(resElements)) {
        for (XXServiceResourceElement resElement : resElements) {
            List<XXServiceResourceElementValue> elementValues = daoManager.getXXServiceResourceElementValue().findByResValueId(resElement.getId());
            if (CollectionUtils.isNotEmpty(elementValues)) {
                for (XXServiceResourceElementValue elementValue : elementValues) {
                    daoManager.getXXServiceResourceElementValue().remove(elementValue.getId());
                }
            }
            daoManager.getXXServiceResourceElement().remove(resElement.getId());
        }
    }
}
Also used : XXServiceResourceElementValue(org.apache.ranger.entity.XXServiceResourceElementValue) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Example 4 with XXServiceResourceElement

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

the class RangerServiceResourceServiceBase method mapEntityToViewBean.

@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
    vObj.setGuid(xObj.getGuid());
    vObj.setVersion(xObj.getVersion());
    vObj.setIsEnabled(xObj.getIsEnabled());
    vObj.setResourceSignature(xObj.getResourceSignature());
    XXService xService = daoMgr.getXXService().getById(xObj.getServiceId());
    vObj.setServiceName(xService.getName());
    List<XXServiceResourceElement> resElementList = daoMgr.getXXServiceResourceElement().findByResourceId(xObj.getId());
    Map<String, RangerPolicy.RangerPolicyResource> resourceElements = new HashMap<String, RangerPolicy.RangerPolicyResource>();
    for (XXServiceResourceElement resElement : resElementList) {
        List<String> resValueMapList = daoMgr.getXXServiceResourceElementValue().findValuesByResElementId(resElement.getId());
        XXResourceDef xResDef = daoMgr.getXXResourceDef().getById(resElement.getResDefId());
        RangerPolicyResource policyRes = new RangerPolicyResource();
        policyRes.setIsExcludes(resElement.getIsExcludes());
        policyRes.setIsRecursive(resElement.getIsRecursive());
        policyRes.setValues(resValueMapList);
        resourceElements.put(xResDef.getName(), policyRes);
    }
    vObj.setResourceElements(resourceElements);
    return vObj;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXService(org.apache.ranger.entity.XXService) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Aggregations

XXServiceResourceElement (org.apache.ranger.entity.XXServiceResourceElement)4 XXService (org.apache.ranger.entity.XXService)3 XXServiceResourceElementValue (org.apache.ranger.entity.XXServiceResourceElementValue)3 HashMap (java.util.HashMap)2 XXResourceDef (org.apache.ranger.entity.XXResourceDef)2 XXTagResourceMap (org.apache.ranger.entity.XXTagResourceMap)2 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)2 Map (java.util.Map)1 XXServiceDef (org.apache.ranger.entity.XXServiceDef)1 XXServiceResource (org.apache.ranger.entity.XXServiceResource)1 XXTag (org.apache.ranger.entity.XXTag)1 XXTagAttribute (org.apache.ranger.entity.XXTagAttribute)1 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)1 RangerServiceNotFoundException (org.apache.ranger.plugin.util.RangerServiceNotFoundException)1