use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class ServiceUtil method toVXResource.
public VXResource toVXResource(RangerPolicy policy, RangerService service) {
if (policy == null || service == null || toAssetType(service.getType()) == null) {
return null;
}
VXResource ret = new VXResource();
rangerObjectToDataObject(policy, ret);
ret.setAssetName(policy.getService());
ret.setAssetId(service.getId());
ret.setAssetType(toAssetType(service.getType()));
ret.setPolicyName(policy.getName());
ret.setDescription(policy.getDescription());
ret.setGuid(policy.getGuid());
ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED);
List<VXAuditMap> auditList = null;
if (policy.getIsAuditEnabled()) {
VXAuditMap auditMap = new VXAuditMap();
auditMap.setResourceId(policy.getId());
auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL);
auditList = new ArrayList<VXAuditMap>();
auditList.add(auditMap);
}
ret.setAuditList(auditList);
for (Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) {
RangerPolicy.RangerPolicyResource res = e.getValue();
String resType = e.getKey();
String resString = getResourceString(res.getValues());
if ("path".equalsIgnoreCase(resType)) {
ret.setName(resString);
ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE);
} else if ("table".equalsIgnoreCase(resType)) {
ret.setTables(resString);
ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION);
} else if ("column-family".equalsIgnoreCase(resType)) {
ret.setColumnFamilies(resString);
} else if ("column".equalsIgnoreCase(resType)) {
ret.setColumns(resString);
ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION);
} else if ("database".equalsIgnoreCase(resType)) {
ret.setDatabases(resString);
} else if ("udf".equalsIgnoreCase(resType)) {
ret.setUdfs(resString);
} else if ("topology".equalsIgnoreCase(resType)) {
ret.setTopologies(resString);
} else if ("service".equalsIgnoreCase(resType)) {
ret.setServices(resString);
} else if (resType.equalsIgnoreCase("hiveservice")) {
ret.setHiveServices(resString);
}
}
updateResourceName(ret);
List<VXPermMap> permMapList = getVXPermMapList(policy);
ret.setPermMapList(permMapList);
return ret;
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserREST method test55createXAuditMapNull.
@Test
public void test55createXAuditMapNull() {
VXAuditMap testvXAuditMap = createVXAuditMapObj();
testvXAuditMap.setResourceId(null);
VXAuditMap retvXAuditMap = xUserRest.createXAuditMap(null);
assertNull(retvXAuditMap);
Mockito.verify(xUserMgr).createXAuditMap(null);
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserREST method test56updateXAuditMap.
@Test
public void test56updateXAuditMap() {
VXAuditMap testvXAuditMap = createVXAuditMapObj();
testvXAuditMap.setResourceId(id);
Mockito.when(xUserMgr.updateXAuditMap(testvXAuditMap)).thenReturn(testvXAuditMap);
VXResource testVxResource = createVXResource();
Mockito.when(xResourceService.readResource(testvXAuditMap.getResourceId())).thenReturn(testVxResource);
VXAuditMap retvXAuditMap = xUserRest.updateXAuditMap(testvXAuditMap);
assertEquals(testvXAuditMap.getId(), retvXAuditMap.getId());
assertEquals(testvXAuditMap.getClass(), retvXAuditMap.getClass());
assertNotNull(retvXAuditMap);
Mockito.verify(xUserMgr).updateXAuditMap(testvXAuditMap);
Mockito.verify(xResourceService).readResource(testvXAuditMap.getResourceId());
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserREST method test50getXAuditMapVXAuditMapNull.
@Test
public void test50getXAuditMapVXAuditMapNull() {
VXAuditMap testvXAuditMap = createVXAuditMapObj();
Mockito.when(xUserMgr.getXAuditMap(testvXAuditMap.getResourceId())).thenReturn(testvXAuditMap);
Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any())).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
VXAuditMap retVXAuditMap = xUserRest.getXAuditMap(testvXAuditMap.getResourceId());
assertEquals(testvXAuditMap.getId(), retVXAuditMap.getId());
assertEquals(testvXAuditMap.getClass(), retVXAuditMap.getClass());
assertNotNull(retVXAuditMap);
Mockito.verify(xUserMgr).getXAuditMap(testvXAuditMap.getResourceId());
Mockito.verify(xResourceService).readResource(null);
Mockito.verify(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any()));
}
use of org.apache.ranger.view.VXAuditMap in project ranger by apache.
the class TestXUserREST method test58updateXAuditMapVXResourceNull.
@Test
public void test58updateXAuditMapVXResourceNull() {
VXAuditMap vXAuditMap = null;
VXAuditMap retvXAuditMap = xUserRest.updateXAuditMap(vXAuditMap);
assertNull(retvXAuditMap);
}
Aggregations