Search in sources :

Example 56 with RangerResourceDef

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

the class ServiceDefUtil method getLeafResourceDef.

public static RangerResourceDef getLeafResourceDef(RangerServiceDef serviceDef, Map<String, RangerPolicy.RangerPolicyResource> policyResource) {
    RangerResourceDef ret = null;
    if (serviceDef != null && policyResource != null) {
        for (Map.Entry<String, RangerPolicy.RangerPolicyResource> entry : policyResource.entrySet()) {
            if (!isEmpty(entry.getValue())) {
                String resource = entry.getKey();
                RangerResourceDef resourceDef = ServiceDefUtil.getResourceDef(serviceDef, resource);
                if (resourceDef != null && resourceDef.getLevel() != null) {
                    if (ret == null) {
                        ret = resourceDef;
                    } else if (ret.getLevel() < resourceDef.getLevel()) {
                        ret = resourceDef;
                    }
                }
            }
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 57 with RangerResourceDef

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

the class RangerServiceDefValidator method isValidResources.

boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("==> RangerServiceDefValidator.isValidResources(%s, %s)", serviceDef, failures));
    }
    boolean valid = true;
    List<RangerResourceDef> resources = serviceDef.getResources();
    if (CollectionUtils.isEmpty(resources)) {
        ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_MISSING_FIELD;
        failures.add(new ValidationFailureDetailsBuilder().field("resources").isMissing().errorCode(error.getErrorCode()).becauseOf(error.getMessage("resources")).build());
        valid = false;
    } else {
        Set<String> names = new HashSet<String>(resources.size());
        Set<Long> ids = new HashSet<Long>(resources.size());
        for (RangerResourceDef resource : resources) {
            /*
				 * While id is the natural key, name is a surrogate key.  At several places code expects resource name to be unique within a service.
				 */
            valid = isUnique(resource.getName(), names, "resource name", "resources", failures) && valid;
            valid = isUnique(resource.getItemId(), ids, "resource itemId", "resources", failures) && valid;
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("<== RangerServiceDefValidator.isValidResources(%s, %s): %s", serviceDef, failures, valid));
    }
    return valid;
}
Also used : ValidationErrorCode(org.apache.ranger.plugin.errors.ValidationErrorCode) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef) HashSet(java.util.HashSet)

Aggregations

RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)57 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)16 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)14 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)13 Date (java.util.Date)12 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)12 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)11 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)11 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)11 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)11 List (java.util.List)8 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 XXResourceDef (org.apache.ranger.entity.XXResourceDef)5 VXString (org.apache.ranger.view.VXString)5 RangerServiceDefHelper (org.apache.ranger.plugin.model.validation.RangerServiceDefHelper)4 RangerResourceMatcher (org.apache.ranger.plugin.resourcematcher.RangerResourceMatcher)4 XXResourceDefDao (org.apache.ranger.db.XXResourceDefDao)3