Search in sources :

Example 71 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class AbstractPredicateUtil method addPredicateForServiceTypeId.

private Predicate addPredicateForServiceTypeId(final String serviceTypeId, List<Predicate> predicates) {
    if (StringUtils.isEmpty(serviceTypeId)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerServiceDef) {
                RangerServiceDef serviceDef = (RangerServiceDef) object;
                Long svcDefId = serviceDef.getId();
                if (svcDefId != null) {
                    ret = StringUtils.equals(serviceTypeId, svcDefId.toString());
                }
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerBaseModelObject(org.apache.ranger.plugin.model.RangerBaseModelObject) Predicate(org.apache.commons.collections.Predicate)

Example 72 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class AbstractServiceStore method updateTagServiceDefForDeletingAccessTypes.

private void updateTagServiceDefForDeletingAccessTypes(String serviceDefName) throws Exception {
    if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME.equals(serviceDefName)) {
        return;
    }
    RangerServiceDef tagServiceDef;
    try {
        tagServiceDef = this.getServiceDef(EmbeddedServiceDefsUtil.instance().getTagServiceDefId());
    } catch (Exception e) {
        LOG.error("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes(" + serviceDefName + "): could not find TAG ServiceDef.. ", e);
        throw e;
    }
    if (tagServiceDef == null) {
        LOG.error("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes(" + serviceDefName + "): could not find TAG ServiceDef.. ");
        return;
    }
    List<RangerServiceDef.RangerAccessTypeDef> accessTypes = new ArrayList<>();
    for (RangerServiceDef.RangerAccessTypeDef accessType : tagServiceDef.getAccessTypes()) {
        if (accessType.getName().startsWith(serviceDefName + COMPONENT_ACCESSTYPE_SEPARATOR)) {
            accessTypes.add(accessType);
        }
    }
    tagServiceDef.getAccessTypes().removeAll(accessTypes);
    updateTagServiceDefForDeletingDataMaskDef(tagServiceDef, serviceDefName);
    updateTagServiceDefForDeletingRowFilterDef(tagServiceDef, serviceDefName);
    updateResourceInTagServiceDef(tagServiceDef);
    try {
        updateServiceDef(tagServiceDef);
        LOG.info("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes -- updated TAG service def with " + serviceDefName + " access types");
    } catch (Exception e) {
        LOG.error("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes -- Failed to update TAG ServiceDef.. ", e);
        throw e;
    }
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList)

Example 73 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class AbstractServiceStore method updateTagServiceDefForUpdatingAccessTypes.

private void updateTagServiceDefForUpdatingAccessTypes(RangerServiceDef serviceDef) throws Exception {
    if (StringUtils.equals(serviceDef.getName(), EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME)) {
        return;
    }
    if (EmbeddedServiceDefsUtil.instance().getTagServiceDefId() == -1) {
        LOG.info("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes(" + serviceDef.getName() + "): tag service-def does not exist");
    }
    RangerServiceDef tagServiceDef;
    try {
        tagServiceDef = this.getServiceDef(EmbeddedServiceDefsUtil.instance().getTagServiceDefId());
    } catch (Exception e) {
        LOG.error("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes" + serviceDef.getName() + "): could not find TAG ServiceDef.. ", e);
        throw e;
    }
    if (tagServiceDef == null) {
        LOG.error("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes(" + serviceDef.getName() + "): could not find TAG ServiceDef.. ");
        return;
    }
    String serviceDefName = serviceDef.getName();
    String prefix = serviceDefName + COMPONENT_ACCESSTYPE_SEPARATOR;
    List<RangerServiceDef.RangerAccessTypeDef> svcDefAccessTypes = serviceDef.getAccessTypes();
    List<RangerServiceDef.RangerAccessTypeDef> tagDefAccessTypes = tagServiceDef.getAccessTypes();
    long itemIdOffset = serviceDef.getId() * (MAX_ACCESS_TYPES_IN_SERVICE_DEF + 1);
    boolean updateNeeded = updateTagAccessTypeDefs(svcDefAccessTypes, tagDefAccessTypes, itemIdOffset, prefix);
    if (updateTagServiceDefForUpdatingDataMaskDef(tagServiceDef, serviceDef, itemIdOffset, prefix)) {
        updateNeeded = true;
    }
    if (updateTagServiceDefForUpdatingRowFilterDef(tagServiceDef, serviceDef, itemIdOffset, prefix)) {
        updateNeeded = true;
    }
    boolean resourceUpdated = updateResourceInTagServiceDef(tagServiceDef);
    updateNeeded = updateNeeded || resourceUpdated;
    if (updateNeeded) {
        try {
            updateServiceDef(tagServiceDef);
            LOG.info("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes -- updated TAG service def with " + serviceDefName + " access types");
        } catch (Exception e) {
            LOG.error("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes -- Failed to update TAG ServiceDef.. ", e);
            throw e;
        }
    }
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 74 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class EmbeddedServiceDefsUtil method getOrCreateServiceDef.

private RangerServiceDef getOrCreateServiceDef(ServiceStore store, String serviceDefName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EmbeddedServiceDefsUtil.getOrCreateServiceDef(" + serviceDefName + ")");
    }
    RangerServiceDef ret = null;
    boolean createServiceDef = (CollectionUtils.isEmpty(supportedServiceDefs) || supportedServiceDefs.contains(serviceDefName));
    try {
        ret = store.getServiceDefByName(serviceDefName);
        if (ret == null && createEmbeddedServiceDefs && createServiceDef) {
            ret = ServiceDefUtil.normalize(loadEmbeddedServiceDef(serviceDefName));
            LOG.info("creating embedded service-def " + serviceDefName);
            if (ret.getId() != null) {
                store.setPopulateExistingBaseFields(true);
                try {
                    ret = store.createServiceDef(ret);
                } finally {
                    store.setPopulateExistingBaseFields(false);
                }
            } else {
                ret = store.createServiceDef(ret);
            }
            LOG.info("created embedded service-def " + serviceDefName);
        }
    } catch (Exception excp) {
        LOG.fatal("EmbeddedServiceDefsUtil.getOrCreateServiceDef(): failed to load/create serviceType " + serviceDefName, excp);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== EmbeddedServiceDefsUtil.getOrCreateServiceDef(" + serviceDefName + "): " + ret);
    }
    return ret;
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 75 with RangerServiceDef

use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.

the class EmbeddedServiceDefsUtil method loadEmbeddedServiceDef.

private RangerServiceDef loadEmbeddedServiceDef(String serviceType) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EmbeddedServiceDefsUtil.loadEmbeddedServiceDef(" + serviceType + ")");
    }
    RangerServiceDef ret = null;
    String resource = "/service-defs/ranger-servicedef-" + serviceType + ".json";
    InputStream inStream = getClass().getResourceAsStream(resource);
    InputStreamReader reader = new InputStreamReader(inStream);
    ret = gsonBuilder.fromJson(reader, RangerServiceDef.class);
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EmbeddedServiceDefsUtil.loadEmbeddedServiceDef(" + serviceType + ")");
    }
    return ret;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Aggregations

RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)105 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)38 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 XXServiceDef (org.apache.ranger.entity.XXServiceDef)18 Date (java.util.Date)15 HashMap (java.util.HashMap)13 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)13 RangerService (org.apache.ranger.plugin.model.RangerService)12 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)12 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)12 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)11 VXString (org.apache.ranger.view.VXString)10 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)9 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)9 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)9 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)8 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)8 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)8 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)7