use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToRangerPolicyForResourceTypeTable.
@Test
public void testToRangerPolicyForResourceTypeTable() {
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("xa_service");
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(true);
rangerPolicyResource.setIsRecursive(false);
rangerPolicyResource.setValue("xa_service");
rangerPolicyResource.setValues(valuesList);
expectedMap.put("table", rangerPolicyResource);
expectedRangerPolicy.setResources(expectedMap);
RangerService rangerService = new RangerService();
rangerService.setName("hive");
VXResource resource = new VXResource();
resource.setId(1L);
resource.setTables("xa_service");
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());
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToRangerPolicyForResourceTypeColumnFamily.
@Test
public void testToRangerPolicyForResourceTypeColumnFamily() {
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("columnFamilies");
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("columnFamilies");
rangerPolicyResource.setValues(valuesList);
expectedMap.put("column-family", rangerPolicyResource);
expectedRangerPolicy.setResources(expectedMap);
RangerService rangerService = new RangerService();
rangerService.setName("hive");
VXResource resource = new VXResource();
resource.setId(1L);
resource.setColumnFamilies("columnFamilies");
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());
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToRangerPolicyForPermGroup.
@Test
public void testToRangerPolicyForPermGroup() {
RangerPolicyItemCondition rpic = new RangerPolicyItemCondition();
List<String> valuesList = new ArrayList<String>();
valuesList.add("10.129.25.56");
rpic.setType("ipaddress");
rpic.setValues(valuesList);
List<String> usersList = new ArrayList<String>();
usersList.add("rangerAdmin");
List<String> groupList = new ArrayList<String>();
List<RangerPolicyItemCondition> listRPIC = new ArrayList<RangerPolicy.RangerPolicyItemCondition>();
listRPIC.add(rpic);
RangerPolicyItemAccess rpia = new RangerPolicyItemAccess();
rpia.setIsAllowed(true);
rpia.setType("drop");
List<RangerPolicyItemAccess> listRPIA = new ArrayList<RangerPolicy.RangerPolicyItemAccess>();
listRPIA.add(rpia);
RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
rangerPolicyItem.setConditions(listRPIC);
rangerPolicyItem.setAccesses(listRPIA);
rangerPolicyItem.setDelegateAdmin(false);
rangerPolicyItem.setUsers(usersList);
rangerPolicyItem.setGroups(groupList);
List<RangerPolicyItem> listRangerPolicyItem = new ArrayList<RangerPolicy.RangerPolicyItem>();
listRangerPolicyItem.add(rangerPolicyItem);
RangerPolicy expectedRangerPolicy = new RangerPolicy();
expectedRangerPolicy.setId(1L);
expectedRangerPolicy.setName("hive Policy");
expectedRangerPolicy.setService("hive");
expectedRangerPolicy.setDescription("hive policy description");
expectedRangerPolicy.setPolicyItems(listRangerPolicyItem);
VXPermMap vXPermMap = new VXPermMap();
vXPermMap.setId(5L);
vXPermMap.setGroupName("myGroup");
vXPermMap.setPermGroup("permGroup");
vXPermMap.setUserName("rangerAdmin");
vXPermMap.setPermType(12);
vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER);
vXPermMap.setIpAddress("10.129.25.56");
List<VXPermMap> vXPermMapList = new ArrayList<VXPermMap>();
vXPermMapList.add(vXPermMap);
VXAuditMap vXAuditMap = new VXAuditMap();
vXAuditMap.setId(1L);
vXAuditMap.setOwner("rangerAdmin");
List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
vXAuditMapList.add(vXAuditMap);
RangerService rangerService = new RangerService();
rangerService.setName("hive");
rangerService.setType("hive");
VXResource resource = new VXResource();
resource.setId(1L);
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);
resource.setPermMapList(vXPermMapList);
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.getPolicyItems(), actualRangerPolicy.getPolicyItems());
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToRangerPolicyForResourceTypeColumn.
@Test
public void testToRangerPolicyForResourceTypeColumn() {
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("column");
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(true);
rangerPolicyResource.setIsRecursive(false);
rangerPolicyResource.setValue("column");
rangerPolicyResource.setValues(valuesList);
expectedMap.put("column", rangerPolicyResource);
expectedRangerPolicy.setResources(expectedMap);
RangerService rangerService = new RangerService();
rangerService.setName("hive");
VXResource resource = new VXResource();
resource.setId(1L);
resource.setColumns("column");
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());
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestServiceUtil method testToVXResourceForTablesColumnsAndDatabase.
@Test
public void testToVXResourceForTablesColumnsAndDatabase() {
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("/myDatabase/myTable/myColumn");
expectedVXResource.setTables("myTable");
expectedVXResource.setDatabases("myDatabase");
expectedVXResource.setColumns("myColumn");
expectedVXResource.setGuid(guidString);
expectedVXResource.setPolicyName("hive Policy");
expectedVXResource.setDescription("hive policy description");
expectedVXResource.setResourceType(1);
expectedVXResource.setAssetName("hive");
expectedVXResource.setAssetType(3);
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> valuesListForDatabase = new ArrayList<String>();
valuesListForDatabase.add("myDatabase");
RangerPolicy policy = new RangerPolicy();
policy.setId(1L);
policy.setName("hive Policy");
policy.setService("hive");
policy.setDescription("hive policy description");
policy.setIsEnabled(true);
policy.setGuid(guidString);
policy.setIsAuditEnabled(true);
RangerService rangerService = new RangerService();
rangerService.setName("hive");
rangerService.setType("hive");
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("column");
rangerPolicyResourceForColumn.setValues(valuesListForColumn);
rangerPolicyResourceMap.put("column", rangerPolicyResourceForColumn);
RangerPolicyResource rangerPolicyResourceForDatabase = new RangerPolicyResource();
rangerPolicyResourceForDatabase.setIsExcludes(true);
rangerPolicyResourceForDatabase.setIsRecursive(true);
rangerPolicyResourceForDatabase.setValue("database");
rangerPolicyResourceForDatabase.setValues(valuesListForDatabase);
rangerPolicyResourceMap.put("database", rangerPolicyResourceForDatabase);
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.getDatabases(), actualVXResource.getDatabases());
Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId());
Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType());
}
Aggregations