Search in sources :

Example 11 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method testPreventPossibleNullValuesInSourceServiceEventData.

@Test
void testPreventPossibleNullValuesInSourceServiceEventData() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    EventData eventData = ServiceEventData.builder().build();
    AuditEvent source = makeMinimalAuditEvent(actor, eventData);
    underTest = new AuditEventToGrpcAuditEventConverter(createMockUtilizer(ServiceEventData.class), mockBuilderProvider);
    underTest.convert(source);
    verify(mockAuditEventBuilderUpdater, times(1)).update(any(), any());
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) EventData(com.sequenceiq.cloudbreak.audit.model.EventData) Test(org.junit.jupiter.api.Test)

Example 12 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method convertActorCrnNoEventData.

@Test
void convertActorCrnNoEventData() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    AuditEvent source = makeAuditEvent(actor, null);
    underTest.convert(source);
    assertGeneric();
    verify(mockAuditEventBuilder, times(1)).setActorCrn(any());
    verify(mockAuditEventBuilder, times(1)).setActorCrn(USER_CRN);
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 13 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method testPreventPossibleNullValuesInSouceApiRequestData.

@Test
void testPreventPossibleNullValuesInSouceApiRequestData() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    EventData eventData = ApiRequestData.builder().build();
    AuditEvent source = makeMinimalAuditEvent(actor, eventData);
    underTest = new AuditEventToGrpcAuditEventConverter(createMockUtilizer(ApiRequestData.class), mockBuilderProvider);
    underTest.convert(source);
    verify(mockAuditEventBuilderUpdater, times(1)).update(any(), any());
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) EventData(com.sequenceiq.cloudbreak.audit.model.EventData) Test(org.junit.jupiter.api.Test)

Example 14 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method convertWithServiceEventData.

@Test
void convertWithServiceEventData() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    EventData eventData = ServiceEventData.builder().withVersion(SERVICE_EVENT_VERSION).withEventDetails(SERVICE_EVENT_DETAILS).build();
    AuditEvent source = makeAuditEvent(actor, eventData);
    underTest = new AuditEventToGrpcAuditEventConverter(createMockUtilizer(ServiceEventData.class), mockBuilderProvider);
    underTest.convert(source);
    assertGeneric();
    verify(mockAuditEventBuilderUpdater, times(1)).update(any(), any());
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) EventData(com.sequenceiq.cloudbreak.audit.model.EventData) Test(org.junit.jupiter.api.Test)

Example 15 with AuditEvent

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

the class AuditService method auditRestApi.

@Async
public void auditRestApi(Map<String, Object> requestParameters, boolean mutating, String userAgent, String userCrn, String accountId, String sourceIp) {
    AuditEvent event = null;
    try {
        ApiRequestData apiRequestData = ApiRequestData.builder().withApiVersion(periscopeVersion).withMutating(mutating).withRequestParameters(new Json(requestParameters).getValue()).withUserAgent(userAgent).build();
        event = AuditEvent.builder().withAccountId(accountId).withActor(ActorCrn.builder().withActorCrn(userCrn).build()).withEventData(apiRequestData).withEventName(AuditEventName.MANAGE_AUTOSCALE_DATAHUB_CLUSTER).withEventSource(Crn.Service.DATAHUB).withSourceIp(sourceIp).build();
        auditClient.createAuditEvent(event);
    } catch (Exception ex) {
        LOGGER.warn("API Audit event creation failed, error : '{}', event : '{}'", ex.getMessage(), event, ex);
    }
}
Also used : ApiRequestData(com.sequenceiq.cloudbreak.audit.model.ApiRequestData) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Json(com.sequenceiq.periscope.model.json.Json) Async(org.springframework.scheduling.annotation.Async)

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