Java Code Examples for org.apache.ranger.audit.model.AuthzAuditEvent#setEventId()
The following examples show how to use
org.apache.ranger.audit.model.AuthzAuditEvent#setEventId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangerDefaultAuditHandler.java From ranger with Apache License 2.0 | 6 votes |
private void populateDefaults(AuthzAuditEvent auditEvent) { if( auditEvent.getAclEnforcer() == null || auditEvent.getAclEnforcer().isEmpty()) { auditEvent.setAclEnforcer("ranger-acl"); // TODO: review } if (auditEvent.getAgentHostname() == null || auditEvent.getAgentHostname().isEmpty()) { auditEvent.setAgentHostname(MiscUtil.getHostname()); } if (auditEvent.getLogType() == null || auditEvent.getLogType().isEmpty()) { auditEvent.setLogType("RangerAudit"); } if (auditEvent.getEventId() == null || auditEvent.getEventId().isEmpty()) { auditEvent.setEventId(generateNextAuditEventId()); } if (auditEvent.getAgentId() == null) { auditEvent.setAgentId(MiscUtil.getApplicationType()); } auditEvent.setSeqNum(sequenceNumber++); }
Example 2
Source File: BufferedAuditProvider.java From ranger with Apache License 2.0 | 6 votes |
@Override public boolean log(AuditEventBase event) { if (event instanceof AuthzAuditEvent) { AuthzAuditEvent authzEvent = (AuthzAuditEvent) event; if (authzEvent.getAgentHostname() == null) { authzEvent.setAgentHostname(MiscUtil.getHostname()); } if (authzEvent.getLogType() == null) { authzEvent.setLogType("RangerAudit"); } if (authzEvent.getEventId() == null) { authzEvent.setEventId(MiscUtil.generateUniqueId()); } } if (!mBuffer.add(event)) { logFailedEvent(event); return false; } return true; }
Example 3
Source File: ElasticSearchAccessAuditsServiceTest.java From ranger with Apache License 2.0 | 5 votes |
private AuthzAuditEvent getAuthzAuditEvent() { AuthzAuditEvent event = new AuthzAuditEvent(); event.setAccessResult((short) 1); event.setAccessType(""); event.setAclEnforcer(""); event.setAction(""); event.setAdditionalInfo(""); event.setAgentHostname(""); event.setAgentId(""); event.setClientIP(""); event.setClusterName(""); event.setClientType(""); event.setEventCount(1); event.setEventDurationMS(1); event.setEventId(""); event.setEventTime(new Date()); event.setLogType(""); event.setPolicyId(1); event.setPolicyVersion(1l); event.setRepositoryName(""); event.setRequestData(""); event.setRepositoryName(""); event.setRepositoryType(1); event.setResourcePath(""); event.setResultReason(""); event.setSeqNum(1); event.setSessionId(""); event.setTags(new HashSet<>()); event.setUser(""); event.setZoneName(""); return event; }
Example 4
Source File: SolrAuditProvider.java From ranger with Apache License 2.0 | 4 votes |
@Override public boolean log(AuditEventBase event) { if (!(event instanceof AuthzAuditEvent)) { LOG.error(event.getClass().getName() + " audit event class type is not supported"); return false; } AuthzAuditEvent authzEvent = (AuthzAuditEvent) event; // TODO: This should be done at a higher level if (authzEvent.getAgentHostname() == null) { authzEvent.setAgentHostname(MiscUtil.getHostname()); } if (authzEvent.getLogType() == null) { authzEvent.setLogType("RangerAudit"); } if (authzEvent.getEventId() == null) { authzEvent.setEventId(MiscUtil.generateUniqueId()); } try { if (solrClient == null) { connect(); if (solrClient == null) { // Solr is still not initialized. So need to throw error return false; } } if (lastFailTime > 0) { long diff = System.currentTimeMillis() - lastFailTime; if (diff < retryWaitTime) { if (LOG.isDebugEnabled()) { LOG.debug("Ignore sending audit. lastConnect=" + diff + " ms"); } return false; } } // Convert AuditEventBase to Solr document final SolrInputDocument document = toSolrDoc(authzEvent); final Collection<SolrInputDocument> docs = Collections.singletonList(document); final UpdateResponse response = SolrAppUtil.addDocsToSolr(solrClient, docs); if (response.getStatus() != 0) { lastFailTime = System.currentTimeMillis(); // System.out.println("Response=" + response.toString() // + ", status= " + response.getStatus() + ", event=" // + event); // throw new Exception("Aborting. event=" + event + // ", response=" // + response.toString()); } else { lastFailTime = 0; } } catch (Throwable t) { LOG.error("Error sending message to Solr", t); return false; } return true; }
Example 5
Source File: KafkaAuditProvider.java From ranger with Apache License 2.0 | 4 votes |
@Override public boolean log(AuditEventBase event) { if (event instanceof AuthzAuditEvent) { AuthzAuditEvent authzEvent = (AuthzAuditEvent) event; if (authzEvent.getAgentHostname() == null) { authzEvent.setAgentHostname(MiscUtil.getHostname()); } if (authzEvent.getLogType() == null) { authzEvent.setLogType("RangerAudit"); } if (authzEvent.getEventId() == null) { authzEvent.setEventId(MiscUtil.generateUniqueId()); } } String message = MiscUtil.stringify(event); try { if (producer != null) { // TODO: Add partition key final ProducerRecord<String, String> keyedMessage = new ProducerRecord<String, String>( topic, message); MiscUtil.executePrivilegedAction(new PrivilegedAction<Void>() { @Override public Void run(){ producer.send(keyedMessage); return null; }; }); } else { LOG.info("AUDIT LOG (Kafka Down):" + message); } } catch (Throwable t) { LOG.error("Error sending message to Kafka topic. topic=" + topic + ", message=" + message, t); return false; } return true; }