Search in sources :

Example 31 with RangerPolicy

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

the class AbstractPredicateUtil method addPredicateForPolicyName.

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

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                ret = StringUtils.equals(policyName, policy.getName());
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerBaseModelObject(org.apache.ranger.plugin.model.RangerBaseModelObject) Predicate(org.apache.commons.collections.Predicate)

Example 32 with RangerPolicy

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

the class AbstractPredicateUtil method addPredicateForResources.

private Predicate addPredicateForResources(final Map<String, String> resources, List<Predicate> predicates) {
    if (MapUtils.isEmpty(resources)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                if (!MapUtils.isEmpty(policy.getResources())) {
                    int numFound = 0;
                    for (String name : resources.keySet()) {
                        boolean isMatch = false;
                        RangerPolicyResource policyResource = policy.getResources().get(name);
                        if (policyResource != null && !CollectionUtils.isEmpty(policyResource.getValues())) {
                            String val = resources.get(name);
                            if (policyResource.getValues().contains(val)) {
                                isMatch = true;
                            } else {
                                for (String policyResourceValue : policyResource.getValues()) {
                                    if (FilenameUtils.wildcardMatch(val, policyResourceValue)) {
                                        isMatch = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (isMatch) {
                            numFound++;
                        } else {
                            break;
                        }
                    }
                    ret = numFound == resources.size();
                }
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) RangerBaseModelObject(org.apache.ranger.plugin.model.RangerBaseModelObject) Predicate(org.apache.commons.collections.Predicate)

Example 33 with RangerPolicy

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

the class AbstractPredicateUtil method addPredicateForPartialPolicyName.

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

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                ret = StringUtils.containsIgnoreCase(policy.getName(), policyName);
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerBaseModelObject(org.apache.ranger.plugin.model.RangerBaseModelObject) Predicate(org.apache.commons.collections.Predicate)

Example 34 with RangerPolicy

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

the class AbstractPredicateUtil method addPredicateForGroupName.

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

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                List<?>[] policyItemsList = new List<?>[] { policy.getPolicyItems(), policy.getDenyPolicyItems(), policy.getAllowExceptions(), policy.getDenyExceptions(), policy.getDataMaskPolicyItems(), policy.getRowFilterPolicyItems() };
                for (List<?> policyItemsObj : policyItemsList) {
                    @SuppressWarnings("unchecked") List<RangerPolicyItem> policyItems = (List<RangerPolicyItem>) policyItemsObj;
                    for (RangerPolicyItem policyItem : policyItems) {
                        if (!policyItem.getGroups().isEmpty()) {
                            for (String group : policyItem.getGroups()) {
                                if (StringUtils.containsIgnoreCase(group, groupName)) {
                                    ret = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (ret) {
                        break;
                    }
                }
            } else {
                ret = true;
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerBaseModelObject(org.apache.ranger.plugin.model.RangerBaseModelObject) ArrayList(java.util.ArrayList) List(java.util.List) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) Predicate(org.apache.commons.collections.Predicate)

Example 35 with RangerPolicy

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

the class ServicePredicateUtil method addPredicateForServiceType.

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

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerPolicy) {
                RangerPolicy policy = (RangerPolicy) object;
                ret = StringUtils.equals(serviceType, getServiceType(policy.getService()));
            } else if (object instanceof RangerService) {
                RangerService service = (RangerService) object;
                ret = StringUtils.equals(serviceType, service.getType());
            } else if (object instanceof RangerServiceDef) {
                RangerServiceDef serviceDef = (RangerServiceDef) object;
                ret = StringUtils.equals(serviceType, serviceDef.getName());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) Predicate(org.apache.commons.collections.Predicate)

Aggregations

RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)196 ArrayList (java.util.ArrayList)78 Test (org.junit.Test)73 RangerService (org.apache.ranger.plugin.model.RangerService)52 VXString (org.apache.ranger.view.VXString)48 HashMap (java.util.HashMap)38 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)36 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)33 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)30 WebApplicationException (javax.ws.rs.WebApplicationException)29 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)27 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)26 Path (javax.ws.rs.Path)23 Produces (javax.ws.rs.Produces)22 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)20 Date (java.util.Date)19 IOException (java.io.IOException)18 XXService (org.apache.ranger.entity.XXService)18 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)16 RangerPolicyList (org.apache.ranger.view.RangerPolicyList)15