Search in sources :

Example 66 with RangerServiceDef

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

the class RangerServiceDefService method getAllServiceDefs.

public List<RangerServiceDef> getAllServiceDefs() {
    List<XXServiceDef> xxServiceDefList = daoMgr.getXXServiceDef().getAll();
    List<RangerServiceDef> serviceDefList = new ArrayList<RangerServiceDef>();
    for (XXServiceDef xxServiceDef : xxServiceDefList) {
        RangerServiceDef serviceDef = populateViewBean(xxServiceDef);
        serviceDefList.add(serviceDef);
    }
    return serviceDefList;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList)

Example 67 with RangerServiceDef

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

the class TestRangerServiceHBase method setup.

@Before
public void setup() {
    configs = new HashMap<String, String>();
    lookupContext = new ResourceLookupContext();
    buildHbaseConnectionConfig();
    buildLookupContext();
    sd = new RangerServiceDef(sdName, "org.apache.ranger.services.hbase.RangerServiceHBase", "TestService", "test servicedef description", null, null, null, null, null, null, null);
    svc = new RangerService(sdName, serviceName, "unit test hbase resource lookup and validateConfig", null, configs);
    svcHBase = new RangerServiceHBase();
    svcHBase.init(sd, svc);
}
Also used : ResourceLookupContext(org.apache.ranger.plugin.service.ResourceLookupContext) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) Before(org.junit.Before)

Example 68 with RangerServiceDef

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

the class RangerOptimizedPolicyEvaluator method computeEvalOrder.

public int computeEvalOrder() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> RangerOptimizedPolicyEvaluator.computeEvalOrder()");
    }
    int evalOrder = RANGER_POLICY_EVAL_SCORE_DEFAULT;
    RangerServiceDef serviceDef = getServiceDef();
    List<RangerServiceDef.RangerResourceDef> resourceDefs = serviceDef.getResources();
    RangerPolicy policy = getPolicy();
    List<LevelResourceNames> tmpList = new ArrayList<>();
    for (Map.Entry<String, RangerPolicy.RangerPolicyResource> kv : policy.getResources().entrySet()) {
        String resourceName = kv.getKey();
        RangerPolicy.RangerPolicyResource policyResource = kv.getValue();
        List<String> resourceValues = policyResource.getValues();
        if (CollectionUtils.isNotEmpty(resourceValues)) {
            for (RangerServiceDef.RangerResourceDef resourceDef : resourceDefs) {
                if (resourceName.equals(resourceDef.getName())) {
                    tmpList.add(new LevelResourceNames(resourceDef.getLevel(), policyResource));
                    break;
                }
            }
        }
    }
    // Sort in ascending order of levels
    Collections.sort(tmpList);
    int resourceDiscount = 0;
    for (LevelResourceNames item : tmpList) {
        // Expect lowest level first
        boolean foundStarWildcard = false;
        boolean foundQuestionWildcard = false;
        boolean foundMatchAny = false;
        for (String resourceName : item.policyResource.getValues()) {
            if (resourceName.isEmpty() || RANGER_POLICY_EVAL_MATCH_ANY_PATTERN_STRING.equals(resourceName)) {
                foundMatchAny = true;
                break;
            } else if (resourceName.contains(RANGER_POLICY_EVAL_MATCH_ANY_PATTERN_STRING)) {
                foundStarWildcard = true;
            } else if (resourceName.contains(RANGER_POLICY_EVAL_MATCH_ONE_CHARACTER_STRING)) {
                foundQuestionWildcard = true;
            }
        }
        if (foundMatchAny) {
            resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_MATCH_ANY_WILDCARD;
        } else {
            if (foundStarWildcard) {
                resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_HAS_MATCH_ANY_WILDCARD;
            } else if (foundQuestionWildcard) {
                resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_HAS_MATCH_ONE_CHARACTER_WILDCARD;
            }
            RangerPolicy.RangerPolicyResource resource = item.policyResource;
            if (resource.getIsExcludes()) {
                resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESOURCE_DISCOUNT_IS_EXCLUDES;
            }
            if (resource.getIsRecursive()) {
                resourceDiscount += RANGER_POLICY_EVAL_SCORE_RESORUCE_DISCOUNT_IS_RECURSIVE;
            }
        }
    }
    if (needsDynamicEval()) {
        evalOrder += RANGER_POLICY_EVAL_SCORE_DYNAMIC_RESOURCE_EVAL_PENALTY;
    }
    evalOrder -= Math.min(RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_RESOURCE, resourceDiscount);
    if (hasPublicGroup || hasCurrentUser) {
        evalOrder -= RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_USERSGROUPS;
    } else {
        evalOrder -= Math.min(groups.size() + users.size(), RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_USERSGROUPS);
    }
    evalOrder -= Math.round(((float) RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_ACCESS_TYPES * accessPerms.size()) / serviceDef.getAccessTypes().size());
    int customConditionsDiscount = RANGER_POLICY_EVAL_SCORE_MAX_DISCOUNT_CUSTOM_CONDITIONS - (RANGER_POLICY_EVAL_SCORE_CUSTOM_CONDITION_PENALTY * this.getCustomConditionsCount());
    if (customConditionsDiscount > 0) {
        evalOrder -= customConditionsDiscount;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== RangerOptimizedPolicyEvaluator.computeEvalOrder(), policyName:" + policy.getName() + ", priority:" + evalOrder);
    }
    return evalOrder;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 69 with RangerServiceDef

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

the class RangerBasePlugin method getDefaultSvcPolicies.

private ServicePolicies getDefaultSvcPolicies() {
    ServicePolicies ret = null;
    RangerServiceDef serviceDef = getServiceDef();
    if (serviceDef == null) {
        serviceDef = getDefaultServiceDef();
    }
    if (serviceDef != null) {
        ret = new ServicePolicies();
        ret.setServiceDef(serviceDef);
        ret.setServiceName(serviceName);
        ret.setPolicies(new ArrayList<RangerPolicy>());
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 70 with RangerServiceDef

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

the class AbstractPredicateUtil 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 RangerServiceDef) {
                RangerServiceDef serviceDef = (RangerServiceDef) object;
                String svcType = serviceDef.getName();
                ret = StringUtils.equals(svcType, serviceType);
            } 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)

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