Search in sources :

Example 66 with RangerPolicyResource

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

the class TestPublicAPIsv2 method rangerPolicy.

private RangerPolicy rangerPolicy() {
    List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
    List<String> users = new ArrayList<String>();
    List<String> groups = new ArrayList<String>();
    List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
    List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
    RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.setAccesses(accesses);
    rangerPolicyItem.setConditions(conditions);
    rangerPolicyItem.setGroups(groups);
    rangerPolicyItem.setUsers(users);
    rangerPolicyItem.setDelegateAdmin(false);
    policyItems.add(rangerPolicyItem);
    Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
    rangerPolicyResource.setIsExcludes(true);
    rangerPolicyResource.setIsRecursive(true);
    rangerPolicyResource.setValue("1");
    rangerPolicyResource.setValues(users);
    policyResource.put("resource", rangerPolicyResource);
    RangerPolicy policy = new RangerPolicy();
    policy.setId(Id);
    policy.setCreateTime(new Date());
    policy.setDescription("policy");
    policy.setGuid("policyguid");
    policy.setIsEnabled(true);
    policy.setName("HDFS_1-1-20150316062453");
    policy.setUpdatedBy("Admin");
    policy.setUpdateTime(new Date());
    policy.setService("HDFS_1-1-20150316062453");
    policy.setIsAuditEnabled(true);
    policy.setPolicyItems(policyItems);
    policy.setResources(policyResource);
    policy.setService("HDFS_1");
    return policy;
}
Also used : HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) Date(java.util.Date) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) RangerPolicyItemCondition(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition)

Example 67 with RangerPolicyResource

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

the class TestPublicAPIsv2 method rangerPolicy1.

private RangerPolicy rangerPolicy1() {
    List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>();
    List<String> users = new ArrayList<String>();
    List<String> groups = new ArrayList<String>();
    List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>();
    List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
    RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
    rangerPolicyItem.setAccesses(accesses);
    rangerPolicyItem.setConditions(conditions);
    rangerPolicyItem.setGroups(groups);
    rangerPolicyItem.setUsers(users);
    rangerPolicyItem.setDelegateAdmin(false);
    policyItems.add(rangerPolicyItem);
    Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
    rangerPolicyResource.setIsExcludes(true);
    rangerPolicyResource.setIsRecursive(true);
    rangerPolicyResource.setValue("2");
    rangerPolicyResource.setValues(users);
    policyResource.put("resource", rangerPolicyResource);
    RangerPolicy policy = new RangerPolicy();
    policy.setId(Id2);
    policy.setCreateTime(new Date());
    policy.setDescription("policy");
    policy.setGuid("policyguid");
    policy.setIsEnabled(true);
    policy.setName("HDFS_1-1-20150316062454");
    policy.setUpdatedBy("Admin");
    policy.setUpdateTime(new Date());
    policy.setService("HDFS_1-1-20150316062454");
    policy.setIsAuditEnabled(true);
    policy.setPolicyItems(policyItems);
    policy.setResources(policyResource);
    policy.setService("HDFS_2");
    return policy;
}
Also used : HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) Date(java.util.Date) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPolicyItemAccess(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess) RangerPolicyItemCondition(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition)

Example 68 with RangerPolicyResource

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

the class TestServiceUtil method testToVXResourceForTablesColumnFamiliesAndColumn.

@Test
public void testToVXResourceForTablesColumnFamiliesAndColumn() {
    GUIDUtil guid = new GUIDUtil();
    String guidString = guid.genGUID();
    List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
    VXAuditMap vxAuditMap = new VXAuditMap();
    vxAuditMap.setResourceId(1L);
    vxAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
    auditList.add(vxAuditMap);
    VXResource expectedVXResource = new VXResource();
    expectedVXResource.setName("/myTable/myColumnFamilies/myColumn");
    expectedVXResource.setTables("myTable");
    expectedVXResource.setColumnFamilies("myColumnFamilies");
    expectedVXResource.setColumns("myColumn");
    expectedVXResource.setGuid(guidString);
    expectedVXResource.setPolicyName("hbase Policy");
    expectedVXResource.setDescription("hbase policy description");
    expectedVXResource.setResourceType(1);
    expectedVXResource.setAssetName("hbase");
    expectedVXResource.setAssetType(2);
    expectedVXResource.setResourceStatus(1);
    expectedVXResource.setTableType(1);
    expectedVXResource.setColumnType(1);
    expectedVXResource.setAuditList(auditList);
    Map<String, RangerPolicyResource> rangerPolicyResourceMap = new HashMap<String, RangerPolicyResource>();
    List<String> valuesListForTable = new ArrayList<String>();
    valuesListForTable.add("myTable");
    List<String> valuesListForColumn = new ArrayList<String>();
    valuesListForColumn.add("myColumn");
    List<String> valuesListForColumnFamilies = new ArrayList<String>();
    valuesListForColumnFamilies.add("myColumnFamilies");
    RangerPolicy policy = new RangerPolicy();
    policy.setId(1L);
    policy.setName("hbase Policy");
    policy.setService("hbase");
    policy.setDescription("hbase policy description");
    policy.setIsEnabled(true);
    policy.setGuid(guidString);
    policy.setIsAuditEnabled(true);
    RangerService rangerService = new RangerService();
    rangerService.setName("hbase");
    rangerService.setType("hbase");
    RangerPolicyResource rangerPolicyResourceForTable = new RangerPolicyResource();
    rangerPolicyResourceForTable.setIsExcludes(true);
    rangerPolicyResourceForTable.setIsRecursive(true);
    rangerPolicyResourceForTable.setValue("table");
    rangerPolicyResourceForTable.setValues(valuesListForTable);
    rangerPolicyResourceMap.put("table", rangerPolicyResourceForTable);
    RangerPolicyResource rangerPolicyResourceForColumn = new RangerPolicyResource();
    rangerPolicyResourceForColumn.setIsExcludes(true);
    rangerPolicyResourceForColumn.setIsRecursive(true);
    rangerPolicyResourceForColumn.setValue("table");
    rangerPolicyResourceForColumn.setValues(valuesListForColumn);
    rangerPolicyResourceMap.put("column", rangerPolicyResourceForColumn);
    RangerPolicyResource rangerPolicyResourceForColumnFamilies = new RangerPolicyResource();
    rangerPolicyResourceForColumnFamilies.setIsExcludes(true);
    rangerPolicyResourceForColumnFamilies.setIsRecursive(true);
    rangerPolicyResourceForColumnFamilies.setValue("table");
    rangerPolicyResourceForColumnFamilies.setValues(valuesListForColumnFamilies);
    rangerPolicyResourceMap.put("column-family", rangerPolicyResourceForColumnFamilies);
    policy.setResources(rangerPolicyResourceMap);
    VXResource actualVXResource = serviceUtil.toVXResource(policy, rangerService);
    Assert.assertNotNull(actualVXResource);
    Assert.assertEquals(expectedVXResource.getName(), actualVXResource.getName());
    Assert.assertEquals(expectedVXResource.getGuid(), actualVXResource.getGuid());
    Assert.assertEquals(expectedVXResource.getPolicyName(), actualVXResource.getPolicyName());
    Assert.assertEquals(expectedVXResource.getResourceType(), actualVXResource.getResourceType());
    Assert.assertEquals(expectedVXResource.getDescription(), actualVXResource.getDescription());
    Assert.assertEquals(expectedVXResource.getAssetName(), actualVXResource.getAssetName());
    Assert.assertEquals(expectedVXResource.getAssetType(), actualVXResource.getAssetType());
    Assert.assertEquals(expectedVXResource.getResourceStatus(), actualVXResource.getResourceStatus());
    Assert.assertEquals(expectedVXResource.getTableType(), actualVXResource.getTableType());
    Assert.assertEquals(expectedVXResource.getColumnType(), actualVXResource.getColumnType());
    Assert.assertEquals(expectedVXResource.getTables(), actualVXResource.getTables());
    Assert.assertEquals(expectedVXResource.getColumns(), actualVXResource.getColumns());
    Assert.assertEquals(expectedVXResource.getColumnFamilies(), actualVXResource.getColumnFamilies());
    Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
    Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) VXAuditMap(org.apache.ranger.view.VXAuditMap) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 69 with RangerPolicyResource

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

the class TestServiceUtil method testToRangerPolicyForResourceTypeDatabase.

@Test
public void testToRangerPolicyForResourceTypeDatabase() {
    RangerPolicy expectedRangerPolicy = new RangerPolicy();
    expectedRangerPolicy.setId(1L);
    expectedRangerPolicy.setName("hive Policy");
    expectedRangerPolicy.setService("hive");
    expectedRangerPolicy.setDescription("hive policy description");
    Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>();
    List<String> valuesList = new ArrayList<String>();
    valuesList.add("databases");
    VXAuditMap vXAuditMap = new VXAuditMap();
    vXAuditMap.setId(1L);
    vXAuditMap.setOwner("rangerAdmin");
    List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
    vXAuditMapList.add(vXAuditMap);
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
    rangerPolicyResource.setIsExcludes(false);
    rangerPolicyResource.setIsRecursive(false);
    rangerPolicyResource.setValue("databases");
    rangerPolicyResource.setValues(valuesList);
    expectedMap.put("database", rangerPolicyResource);
    expectedRangerPolicy.setResources(expectedMap);
    RangerService rangerService = new RangerService();
    rangerService.setName("hive");
    VXResource resource = new VXResource();
    resource.setId(1L);
    resource.setDatabases("databases");
    resource.setUpdateDate(new Date());
    resource.setCreateDate(new Date());
    resource.setOwner("rangerAdmin");
    resource.setUpdatedBy("rangerAdmin");
    resource.setPolicyName("hive Policy");
    resource.setDescription("hive policy description");
    resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED);
    resource.setIsRecursive(1);
    resource.setTableType(1);
    resource.setColumnType(1);
    RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService);
    Assert.assertNotNull(actualRangerPolicy);
    Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId());
    Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName());
    Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService());
    Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription());
    Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) VXAuditMap(org.apache.ranger.view.VXAuditMap) RangerService(org.apache.ranger.plugin.model.RangerService) Date(java.util.Date) Test(org.junit.Test)

Example 70 with RangerPolicyResource

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

the class TestServiceUtil method testToVXResourceForPath.

@Test
public void testToVXResourceForPath() {
    GUIDUtil guid = new GUIDUtil();
    String guidString = guid.genGUID();
    List<VXAuditMap> auditList = new ArrayList<VXAuditMap>();
    VXAuditMap vxAuditMap = new VXAuditMap();
    vxAuditMap.setResourceId(1L);
    vxAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
    auditList.add(vxAuditMap);
    VXResource expectedVXResource = new VXResource();
    expectedVXResource.setName("resource");
    expectedVXResource.setGuid(guidString);
    expectedVXResource.setPolicyName("hdfs Policy");
    expectedVXResource.setDescription("hdfs policy description");
    expectedVXResource.setResourceType(1);
    expectedVXResource.setAssetName("hdfs");
    expectedVXResource.setAssetType(1);
    expectedVXResource.setAuditList(auditList);
    Map<String, RangerPolicyResource> rangerPolicyResourceMap = new HashMap<String, RangerPolicyResource>();
    List<String> valuesList = new ArrayList<String>();
    valuesList.add("resource");
    RangerPolicy policy = new RangerPolicy();
    policy.setId(1L);
    policy.setName("hdfs Policy");
    policy.setService("hdfs");
    policy.setDescription("hdfs policy description");
    policy.setIsEnabled(true);
    policy.setGuid(guidString);
    policy.setIsAuditEnabled(true);
    RangerService rangerService = new RangerService();
    rangerService.setName("hdfs");
    rangerService.setType("hdfs");
    RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
    rangerPolicyResource.setIsExcludes(false);
    rangerPolicyResource.setIsRecursive(true);
    rangerPolicyResource.setValue("/localhost/files");
    rangerPolicyResource.setValues(valuesList);
    rangerPolicyResourceMap.put("path", rangerPolicyResource);
    policy.setResources(rangerPolicyResourceMap);
    VXResource actualVXResource = serviceUtil.toVXResource(policy, rangerService);
    Assert.assertNotNull(actualVXResource);
    Assert.assertEquals(expectedVXResource.getName(), actualVXResource.getName());
    Assert.assertEquals(expectedVXResource.getGuid(), actualVXResource.getGuid());
    Assert.assertEquals(expectedVXResource.getPolicyName(), actualVXResource.getPolicyName());
    Assert.assertEquals(expectedVXResource.getResourceType(), actualVXResource.getResourceType());
    Assert.assertEquals(expectedVXResource.getDescription(), actualVXResource.getDescription());
    Assert.assertEquals(expectedVXResource.getAssetName(), actualVXResource.getAssetName());
    Assert.assertEquals(expectedVXResource.getAssetType(), actualVXResource.getAssetType());
    Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
    Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) HashMap(java.util.HashMap) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) VXAuditMap(org.apache.ranger.view.VXAuditMap) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Aggregations

RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)101 HashMap (java.util.HashMap)65 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)64 ArrayList (java.util.ArrayList)50 Test (org.junit.Test)43 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)35 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)32 Date (java.util.Date)26 RangerService (org.apache.ranger.plugin.model.RangerService)23 VXString (org.apache.ranger.view.VXString)18 RangerPolicyItemCondition (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemCondition)17 VXAuditMap (org.apache.ranger.view.VXAuditMap)15 VXResource (org.apache.ranger.view.VXResource)15 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)12 LinkedHashMap (java.util.LinkedHashMap)10 XXServiceDef (org.apache.ranger.entity.XXServiceDef)8 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)8 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)8 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)8 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)7