use of org.apache.ranger.audit.model.AuthzAuditEvent in project ranger by apache.
the class RangerDefaultAuditHandler method processResult.
@Override
public void processResult(RangerAccessResult result) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerDefaultAuditHandler.processResult(" + result + ")");
}
AuthzAuditEvent event = getAuthzEvents(result);
logAuthzAudit(event);
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerDefaultAuditHandler.processResult(" + result + ")");
}
}
use of org.apache.ranger.audit.model.AuthzAuditEvent in project ranger by apache.
the class RangerDefaultAuditHandler method getAuthzEvents.
public Collection<AuthzAuditEvent> getAuthzEvents(Collection<RangerAccessResult> results) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerDefaultAuditHandler.getAuthzEvents(" + results + ")");
}
List<AuthzAuditEvent> ret = null;
if (results != null) {
// TODO: optimize the number of audit logs created
for (RangerAccessResult result : results) {
AuthzAuditEvent event = getAuthzEvents(result);
if (event == null) {
continue;
}
if (ret == null) {
ret = new ArrayList<>();
}
ret.add(event);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerDefaultAuditHandler.getAuthzEvents(" + results + "): " + ret);
}
return ret;
}
use of org.apache.ranger.audit.model.AuthzAuditEvent in project ranger by apache.
the class RangerHiveAuditHandler method createAuditEvent.
AuthzAuditEvent createAuditEvent(RangerAccessResult result) {
AuthzAuditEvent ret = null;
RangerAccessRequest request = result.getAccessRequest();
RangerAccessResource resource = request.getResource();
String resourcePath = resource != null ? resource.getAsString() : null;
int policyType = result.getPolicyType();
if (policyType == RangerPolicy.POLICY_TYPE_DATAMASK && result.isMaskEnabled()) {
ret = createAuditEvent(result, result.getMaskType(), resourcePath);
} else if (policyType == RangerPolicy.POLICY_TYPE_ROWFILTER) {
ret = createAuditEvent(result, ACCESS_TYPE_ROWFILTER, resourcePath);
} else {
String accessType = null;
if (request instanceof RangerHiveAccessRequest) {
RangerHiveAccessRequest hiveRequest = (RangerHiveAccessRequest) request;
accessType = hiveRequest.getHiveAccessType().toString();
}
if (StringUtils.isEmpty(accessType)) {
accessType = request.getAccessType();
}
ret = createAuditEvent(result, accessType, resourcePath);
}
return ret;
}
use of org.apache.ranger.audit.model.AuthzAuditEvent in project ranger by apache.
the class RangerHiveAuditHandler method createAuditEvent.
AuthzAuditEvent createAuditEvent(RangerAccessResult result, String accessType, String resourcePath) {
RangerAccessRequest request = result.getAccessRequest();
RangerAccessResource resource = request.getResource();
String resourceType = resource != null ? resource.getLeafName() : null;
AuthzAuditEvent auditEvent = super.getAuthzEvents(result);
auditEvent.setAccessType(accessType);
auditEvent.setResourcePath(resourcePath);
// to be consistent with earlier release
auditEvent.setResourceType("@" + resourceType);
if (request instanceof RangerHiveAccessRequest && resource instanceof RangerHiveResource) {
RangerHiveAccessRequest hiveAccessRequest = (RangerHiveAccessRequest) request;
RangerHiveResource hiveResource = (RangerHiveResource) resource;
if (hiveAccessRequest.getHiveAccessType() == HiveAccessType.USE && hiveResource.getObjectType() == HiveObjectType.DATABASE) {
// this should happen only for SHOWDATABASES and USE <db-name> commands
auditEvent.setTags(null);
}
}
return auditEvent;
}
use of org.apache.ranger.audit.model.AuthzAuditEvent in project ranger by apache.
the class RangerHiveAuditHandler method logAuditEventForDfs.
public void logAuditEventForDfs(String userName, String dfsCommand, boolean accessGranted, int repositoryType, String repositoryName) {
AuthzAuditEvent auditEvent = new AuthzAuditEvent();
auditEvent.setAclEnforcer(RangerDefaultAuditHandler.RangerModuleName);
// to be consistent with earlier release
auditEvent.setResourceType("@dfs");
auditEvent.setAccessType("DFS");
auditEvent.setAction("DFS");
auditEvent.setUser(userName);
auditEvent.setAccessResult((short) (accessGranted ? 1 : 0));
auditEvent.setEventTime(new Date());
auditEvent.setRepositoryType(repositoryType);
auditEvent.setRepositoryName(repositoryName);
auditEvent.setRequestData(dfsCommand);
auditEvent.setResourcePath(dfsCommand);
addAuthzAuditEvent(auditEvent);
}
Aggregations