Search in sources :

Example 6 with RangerResourceDef

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

the class TestServiceREST method rangerServiceDef.

private RangerServiceDef rangerServiceDef() {
    List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
    List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
    List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
    List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
    List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
    List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
    RangerServiceDef rangerServiceDef = new RangerServiceDef();
    rangerServiceDef.setId(Id);
    rangerServiceDef.setImplClass("RangerServiceHdfs");
    rangerServiceDef.setLabel("HDFS Repository");
    rangerServiceDef.setDescription("HDFS Repository");
    rangerServiceDef.setRbKeyDescription(null);
    rangerServiceDef.setUpdatedBy("Admin");
    rangerServiceDef.setUpdateTime(new Date());
    rangerServiceDef.setConfigs(configs);
    rangerServiceDef.setResources(resources);
    rangerServiceDef.setAccessTypes(accessTypes);
    rangerServiceDef.setPolicyConditions(policyConditions);
    rangerServiceDef.setContextEnrichers(contextEnrichers);
    rangerServiceDef.setEnums(enums);
    return rangerServiceDef;
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) ArrayList(java.util.ArrayList) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 7 with RangerResourceDef

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

the class ServiceDefUtil method normalizeDataMaskDef.

private static void normalizeDataMaskDef(RangerServiceDef serviceDef) {
    if (serviceDef != null && serviceDef.getDataMaskDef() != null) {
        List<RangerResourceDef> dataMaskResources = serviceDef.getDataMaskDef().getResources();
        List<RangerAccessTypeDef> dataMaskAccessTypes = serviceDef.getDataMaskDef().getAccessTypes();
        if (CollectionUtils.isNotEmpty(dataMaskResources)) {
            List<RangerResourceDef> resources = serviceDef.getResources();
            List<RangerResourceDef> processedDefs = new ArrayList<RangerResourceDef>(dataMaskResources.size());
            for (RangerResourceDef dataMaskResource : dataMaskResources) {
                RangerResourceDef processedDef = dataMaskResource;
                for (RangerResourceDef resourceDef : resources) {
                    if (StringUtils.equals(resourceDef.getName(), dataMaskResource.getName())) {
                        processedDef = ServiceDefUtil.mergeResourceDef(resourceDef, dataMaskResource);
                        break;
                    }
                }
                processedDefs.add(processedDef);
            }
            serviceDef.getDataMaskDef().setResources(processedDefs);
        }
        if (CollectionUtils.isNotEmpty(dataMaskAccessTypes)) {
            List<RangerAccessTypeDef> accessTypes = serviceDef.getAccessTypes();
            List<RangerAccessTypeDef> processedDefs = new ArrayList<RangerAccessTypeDef>(accessTypes.size());
            for (RangerAccessTypeDef dataMaskAccessType : dataMaskAccessTypes) {
                RangerAccessTypeDef processedDef = dataMaskAccessType;
                for (RangerAccessTypeDef accessType : accessTypes) {
                    if (StringUtils.equals(accessType.getName(), dataMaskAccessType.getName())) {
                        processedDef = ServiceDefUtil.mergeAccessTypeDef(accessType, dataMaskAccessType);
                        break;
                    }
                }
                processedDefs.add(processedDef);
            }
            serviceDef.getDataMaskDef().setAccessTypes(processedDefs);
        }
    }
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) ArrayList(java.util.ArrayList) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 8 with RangerResourceDef

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

the class ServiceDefUtil method normalizeRowFilterDef.

private static void normalizeRowFilterDef(RangerServiceDef serviceDef) {
    if (serviceDef != null && serviceDef.getRowFilterDef() != null) {
        List<RangerResourceDef> rowFilterResources = serviceDef.getRowFilterDef().getResources();
        List<RangerAccessTypeDef> rowFilterAccessTypes = serviceDef.getRowFilterDef().getAccessTypes();
        if (CollectionUtils.isNotEmpty(rowFilterResources)) {
            List<RangerResourceDef> resources = serviceDef.getResources();
            List<RangerResourceDef> processedDefs = new ArrayList<RangerResourceDef>(rowFilterResources.size());
            for (RangerResourceDef rowFilterResource : rowFilterResources) {
                RangerResourceDef processedDef = rowFilterResource;
                for (RangerResourceDef resourceDef : resources) {
                    if (StringUtils.equals(resourceDef.getName(), rowFilterResource.getName())) {
                        processedDef = ServiceDefUtil.mergeResourceDef(resourceDef, rowFilterResource);
                        break;
                    }
                }
                processedDefs.add(processedDef);
            }
            serviceDef.getRowFilterDef().setResources(processedDefs);
        }
        if (CollectionUtils.isNotEmpty(rowFilterAccessTypes)) {
            List<RangerAccessTypeDef> accessTypes = serviceDef.getAccessTypes();
            List<RangerAccessTypeDef> processedDefs = new ArrayList<RangerAccessTypeDef>(accessTypes.size());
            for (RangerAccessTypeDef rowFilterAccessType : rowFilterAccessTypes) {
                RangerAccessTypeDef processedDef = rowFilterAccessType;
                for (RangerAccessTypeDef accessType : accessTypes) {
                    if (StringUtils.equals(accessType.getName(), rowFilterAccessType.getName())) {
                        processedDef = ServiceDefUtil.mergeAccessTypeDef(accessType, rowFilterAccessType);
                        break;
                    }
                }
                processedDefs.add(processedDef);
            }
            serviceDef.getRowFilterDef().setAccessTypes(processedDefs);
        }
    }
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) ArrayList(java.util.ArrayList) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 9 with RangerResourceDef

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

the class TestRangerPolicyValidator method test_isValidResourceNames_failures.

@Test
public final void test_isValidResourceNames_failures() {
    String serviceName = "a-service-def";
    // setup service-def
    Date now = new Date();
    when(_serviceDef.getName()).thenReturn(serviceName);
    when(_serviceDef.getUpdateTime()).thenReturn(now);
    List<RangerResourceDef> resourceDefs = _utils.createResourceDefs(resourceDefData_multipleHierarchies);
    when(_serviceDef.getResources()).thenReturn(resourceDefs);
    // setup policy
    Map<String, RangerPolicyResource> policyResources = _utils.createPolicyResourceMap(policyResourceMap_bad);
    when(_policy.getResources()).thenReturn(policyResources);
    Assert.assertFalse("Missing required resource and unknown resource", _validator.isValidResourceNames(_policy, _failures, _serviceDef));
    _utils.checkFailureForSemanticError(_failures, "policy resources");
    // another bad resource map that straddles multiple hierarchies
    policyResources = _utils.createPolicyResourceMap(policyResourceMap_bad_multiple_hierarchies);
    when(_policy.getResources()).thenReturn(policyResources);
    _failures.clear();
    Assert.assertFalse("Policy with resources for multiple hierarchies", _validator.isValidResourceNames(_policy, _failures, _serviceDef));
    _utils.checkFailureForSemanticError(_failures, "policy resources", "incompatible");
    // another bad policy resource map that could match multiple hierarchies but is short on mandatory resources for all of those matches
    policyResources = _utils.createPolicyResourceMap(policyResourceMap_bad_multiple_hierarchies_missing_mandatory);
    when(_policy.getResources()).thenReturn(policyResources);
    _failures.clear();
    Assert.assertFalse("Policy with resources for multiple hierarchies missing mandatory resources for all pontential matches", _validator.isValidResourceNames(_policy, _failures, _serviceDef));
    _utils.checkFailureForSemanticError(_failures, "policy resources", "missing mandatory");
}
Also used : RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) Date(java.util.Date) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef) Test(org.junit.Test)

Example 10 with RangerResourceDef

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

the class TestRangerServiceDefHelper method test_isResourceGraphValid_detectCycle.

@Test
public final void test_isResourceGraphValid_detectCycle() {
    /*
		 * Create a service-def with cycles in resource graph
		 *  A --> B --> C
		 *  ^           |
		 *  |           |
		 *  |---- D <---
		 */
    // A's parent is D, etc.
    RangerResourceDef A = createResourceDef("A", "D");
    RangerResourceDef B = createResourceDef("B", "C");
    RangerResourceDef C = createResourceDef("C", "D");
    RangerResourceDef D = createResourceDef("D", "A");
    // order of resources in list sould not matter
    List<RangerResourceDef> resourceDefs = Lists.newArrayList(A, B, C, D);
    when(_serviceDef.getResources()).thenReturn(resourceDefs);
    _helper = new RangerServiceDefHelper(_serviceDef);
    assertFalse("Graph was valid!", _helper.isResourceGraphValid());
}
Also used : RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef) Test(org.junit.Test)

Aggregations

RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)50 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)15 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)12 Date (java.util.Date)11 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)11 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)10 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)10 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)10 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)10 List (java.util.List)7 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)7 HashSet (java.util.HashSet)5 XXResourceDef (org.apache.ranger.entity.XXResourceDef)5 RangerServiceDefHelper (org.apache.ranger.plugin.model.validation.RangerServiceDefHelper)4 RangerResourceMatcher (org.apache.ranger.plugin.resourcematcher.RangerResourceMatcher)4 VXString (org.apache.ranger.view.VXString)4 HashMap (java.util.HashMap)3 XXResourceDefDao (org.apache.ranger.db.XXResourceDefDao)3