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;
}
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);
}
}
}
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);
}
}
}
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");
}
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());
}
Aggregations