Search in sources :

Example 1 with AuditEvent

use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.

the class AuditServiceTest method testAuditServiceEvent.

@Test
public void testAuditServiceEvent() {
    String auditMessage = "audit service message";
    underTest.auditAutoscaleServiceEvent(ScalingStatus.SUCCESS, auditMessage, "clusterCrn", "user-account", System.currentTimeMillis());
    ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
    verify(auditClient, times(1)).createAuditEvent(captor.capture());
    AuditEvent auditEvent = captor.getValue();
    assertEquals("user-account", auditEvent.getAccountId());
    assertEquals(AUTOSCALE_DATAHUB_CLUSTER, auditEvent.getEventName());
    assertEquals(Crn.Service.DATAHUB, auditEvent.getEventSource());
    assertEquals(Crn.Service.DATAHUB.getName(), ((ActorService) auditEvent.getActor()).getActorServiceName());
    ServiceEventData serviceEventData = (ServiceEventData) auditEvent.getEventData();
    assertNotNull("Event Data should be intialized", serviceEventData.getEventDetails());
    assertTrue("Time stamp should be intialized", serviceEventData.getEventDetails().contains("timestamp"));
}
Also used : ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Test(org.junit.Test)

Example 2 with AuditEvent

use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.

the class CDPAuditStructuredEventHandler method accept.

@Override
public void accept(Event<T> structuredEvent) {
    try {
        T data = structuredEvent.getData();
        CDPOperationDetails operation = data.getOperation();
        CDPEventDataExtractor<T> extractor = eventDataExtractorMap.get(operation.getEventType().name().toLowerCase() + "CDPEventDataExtractor");
        LOGGER.info("Extract audit event as {}", extractor);
        AuditEvent event = AuditEvent.builder().withAccountId(operation.getAccountId()).withActor(ActorCrn.builder().withActorCrn(operation.getUserCrn()).build()).withEventData(extractor.eventData(data)).withEventName(extractor.eventName(data)).withEventSource(extractor.eventSource(data)).withSourceIp(extractor.sourceIp(data)).build();
        auditClient.createAuditEvent(event);
    } catch (UnsupportedOperationException e) {
        LOGGER.debug("Audit log is unnecessary: {}", e.getMessage());
    } catch (Exception e) {
        LOGGER.warn("Cannot perform auditing: {}", e.getMessage(), e);
    }
}
Also used : AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 3 with AuditEvent

use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.

the class LegacyAuditStructuredEventHandler method accept.

@Override
public void accept(Event<T> structuredEvent) {
    try {
        T data = structuredEvent.getData();
        OperationDetails operation = data.getOperation();
        LegacyEventDataExtractor<T> extractor = eventDataExtractorMap.get(operation.getEventType().name().toLowerCase() + "LegacyEventDataExtractor");
        LOGGER.info("Extract audit event as {}", extractor);
        AuditEvent event = AuditEvent.builder().withAccountId(operation.getTenant()).withActor(ActorCrn.builder().withActorCrn(operation.getUserCrn()).build()).withEventData(extractor.eventData(data)).withEventName(extractor.eventName(data)).withEventSource(extractor.eventSource(data)).withSourceIp(extractor.sourceIp(data)).build();
        auditClient.createAuditEvent(event);
    } catch (UnsupportedOperationException e) {
        LOGGER.debug("Audit log is unnecessary: {}", e.getMessage());
    } catch (Exception e) {
        LOGGER.error("Cannot perform auditing: {}", e.getMessage(), e);
    }
}
Also used : OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent)

Example 4 with AuditEvent

use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.

the class AuditEventToGrpcAuditEventConverterTest method convertNoEventData.

@Test
void convertNoEventData() {
    ActorBase actor = ActorService.builder().withActorServiceName(ACTOR_SERVICE_NAME).build();
    AuditEvent source = makeAuditEvent(actor, null);
    underTest.convert(source);
    assertGeneric();
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 5 with AuditEvent

use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.

the class AuditEventToGrpcAuditEventConverterTest method testWhenResultEventDataIsNullThenNoUtilizerCallHappens.

@Test
void testWhenResultEventDataIsNullThenNoUtilizerCallHappens() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    AuditEvent source = makeMinimalAuditEvent(actor, null);
    underTest.convert(source);
    verify(mockAuditEventBuilderUpdater, never()).update(any(), any());
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Test(org.junit.jupiter.api.Test)

Aggregations

AuditEvent (com.sequenceiq.cloudbreak.audit.model.AuditEvent)15 ActorBase (com.sequenceiq.cloudbreak.audit.model.ActorBase)9 Test (org.junit.jupiter.api.Test)9 ServiceEventData (com.sequenceiq.cloudbreak.audit.model.ServiceEventData)7 EventData (com.sequenceiq.cloudbreak.audit.model.EventData)5 ApiRequestData (com.sequenceiq.cloudbreak.audit.model.ApiRequestData)2 Json (com.sequenceiq.periscope.model.json.Json)2 Test (org.junit.Test)2 Async (org.springframework.scheduling.annotation.Async)2 Gson (com.google.gson.Gson)1 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)1 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1