use of org.apache.ranger.entity.XXAuditMap in project ranger by apache.
the class XUserMgr method deleteXAuditMap.
public void deleteXAuditMap(Long id, boolean force) {
xaBizUtil.blockAuditorRoleUser();
if (force) {
XXAuditMap xAuditMap = daoManager.getXXAuditMap().getById(id);
if (xAuditMap != null) {
if (xResourceService.readResource(xAuditMap.getResourceId()) == null) {
throw restErrorUtil.createRESTException("Invalid Input Data - No resource found with Id: " + xAuditMap.getResourceId(), MessageEnums.INVALID_INPUT_DATA);
}
}
xAuditMapService.deleteResource(id);
} else {
throw restErrorUtil.createRESTException("serverMsg.modelMgrBaseDeleteModel", MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
}
}
use of org.apache.ranger.entity.XXAuditMap in project ranger by apache.
the class TestXUserMgr method test89deleteXAuditMap.
@Test
public void test89deleteXAuditMap() {
destroySession();
setup();
VXResource vxresource = new VXResource();
XXAuditMapDao xXAuditMapDao = Mockito.mock(XXAuditMapDao.class);
Mockito.when(daoManager.getXXAuditMap()).thenReturn(xXAuditMapDao);
VXAuditMap vXAuditMap = getVXAuditMap();
XXAuditMap xXAuditMap = new XXAuditMap();
xXAuditMap.setId(vXAuditMap.getId());
xXAuditMap.setResourceId(vXAuditMap.getResourceId());
Mockito.when(xXAuditMapDao.getById(vXAuditMap.getId())).thenReturn(xXAuditMap);
Mockito.when(xResourceService.readResource(xXAuditMap.getResourceId())).thenReturn(vxresource);
Mockito.when(xAuditMapService.deleteResource(Mockito.anyLong())).thenReturn(true);
xUserMgr.deleteXAuditMap(vXAuditMap.getId(), true);
Mockito.when(xResourceService.readResource(xXAuditMap.getResourceId())).thenReturn(null);
Mockito.when(restErrorUtil.createRESTException("Invalid Input Data - No resource found with Id: " + xXAuditMap.getResourceId(), MessageEnums.INVALID_INPUT_DATA)).thenThrow(new WebApplicationException());
thrown.expect(WebApplicationException.class);
xUserMgr.deleteXAuditMap(vXAuditMap.getId(), true);
}
use of org.apache.ranger.entity.XXAuditMap in project ranger by apache.
the class XAuditMapService method mapViewToEntityBean.
@Override
protected XXAuditMap mapViewToEntityBean(VXAuditMap vObj, XXAuditMap mObj, int OPERATION_CONTEXT) {
XXAuditMap ret = null;
if (vObj != null && mObj != null) {
ret = super.mapViewToEntityBean(vObj, mObj, OPERATION_CONTEXT);
XXPortalUser xXPortalUser = null;
if (ret.getAddedByUserId() == null || ret.getAddedByUserId() == 0) {
if (!stringUtil.isEmpty(vObj.getOwner())) {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getOwner());
if (xXPortalUser != null) {
ret.setAddedByUserId(xXPortalUser.getId());
}
}
}
if (ret.getUpdatedByUserId() == null || ret.getUpdatedByUserId() == 0) {
if (!stringUtil.isEmpty(vObj.getUpdatedBy())) {
xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getUpdatedBy());
if (xXPortalUser != null) {
ret.setUpdatedByUserId(xXPortalUser.getId());
}
}
}
}
return ret;
}
use of org.apache.ranger.entity.XXAuditMap in project ranger by apache.
the class PatchMigration_J10002 method mapXResourceToPolicy.
private RangerPolicy mapXResourceToPolicy(RangerPolicy policy, XXResource xRes, RangerService service) {
String serviceName = service.getName();
String serviceType = service.getType();
String name = xRes.getPolicyName();
String description = xRes.getDescription();
Boolean isAuditEnabled = true;
Boolean isEnabled = true;
Map<String, RangerPolicyResource> resources = new HashMap<String, RangerPolicyResource>();
List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>();
XXServiceDef svcDef = daoMgr.getXXServiceDef().findByName(serviceType);
if (svcDef == null) {
logger.error(serviceType + ": service-def not found. Skipping policy '" + name + "'");
return null;
}
List<XXAuditMap> auditMapList = daoMgr.getXXAuditMap().findByResourceId(xRes.getId());
if (stringUtil.isEmpty(auditMapList)) {
isAuditEnabled = false;
}
if (xRes.getResourceStatus() == AppConstants.STATUS_DISABLED) {
isEnabled = false;
}
Boolean isPathRecursive = xRes.getIsRecursive() == RangerCommonEnums.BOOL_TRUE;
Boolean isTableExcludes = xRes.getTableType() == RangerCommonEnums.POLICY_EXCLUSION;
Boolean isColumnExcludes = xRes.getColumnType() == RangerCommonEnums.POLICY_EXCLUSION;
if (StringUtils.equalsIgnoreCase(serviceType, "hdfs")) {
toRangerResourceList(xRes.getName(), "path", Boolean.FALSE, isPathRecursive, resources);
} else if (StringUtils.equalsIgnoreCase(serviceType, "hbase")) {
toRangerResourceList(xRes.getTables(), "table", isTableExcludes, Boolean.FALSE, resources);
toRangerResourceList(xRes.getColumnFamilies(), "column-family", Boolean.FALSE, Boolean.FALSE, resources);
toRangerResourceList(xRes.getColumns(), "column", isColumnExcludes, Boolean.FALSE, resources);
} else if (StringUtils.equalsIgnoreCase(serviceType, "hive")) {
toRangerResourceList(xRes.getDatabases(), "database", Boolean.FALSE, Boolean.FALSE, resources);
toRangerResourceList(xRes.getTables(), "table", isTableExcludes, Boolean.FALSE, resources);
toRangerResourceList(xRes.getColumns(), "column", isColumnExcludes, Boolean.FALSE, resources);
toRangerResourceList(xRes.getUdfs(), "udf", Boolean.FALSE, Boolean.FALSE, resources);
} else if (StringUtils.equalsIgnoreCase(serviceType, "knox")) {
toRangerResourceList(xRes.getTopologies(), "topology", Boolean.FALSE, Boolean.FALSE, resources);
toRangerResourceList(xRes.getServices(), "service", Boolean.FALSE, Boolean.FALSE, resources);
} else if (StringUtils.equalsIgnoreCase(serviceType, "storm")) {
toRangerResourceList(xRes.getTopologies(), "topology", Boolean.FALSE, Boolean.FALSE, resources);
}
policyItems = getPolicyItemListForRes(xRes, svcDef);
policy.setService(serviceName);
policy.setName(name);
policy.setDescription(description);
policy.setIsAuditEnabled(isAuditEnabled);
policy.setIsEnabled(isEnabled);
policy.setResources(resources);
policy.setPolicyItems(policyItems);
policy.setCreateTime(xRes.getCreateTime());
policy.setUpdateTime(xRes.getUpdateTime());
XXPortalUser createdByUser = daoMgr.getXXPortalUser().getById(xRes.getAddedByUserId());
XXPortalUser updByUser = daoMgr.getXXPortalUser().getById(xRes.getUpdatedByUserId());
if (createdByUser != null) {
policy.setCreatedBy(createdByUser.getLoginId());
}
if (updByUser != null) {
policy.setUpdatedBy(updByUser.getLoginId());
}
policy.setId(xRes.getId());
return policy;
}
use of org.apache.ranger.entity.XXAuditMap in project ranger by apache.
the class XResourceService method populateAuditList.
private void populateAuditList(VXResource vXResource) {
List<XXAuditMap> xAuditMapList = daoManager.getXXAuditMap().findByResourceId(vXResource.getId());
List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>();
for (XXAuditMap xAuditMap : xAuditMapList) {
vXAuditMapList.add(xAuditMapService.populateViewBean(xAuditMap));
}
vXResource.setAuditList(vXAuditMapList);
}
Aggregations