Search in sources :

Example 6 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method convertUnknownActorThrows.

@Test
void convertUnknownActorThrows() {
    class Unknown extends ActorBase {
    }
    AuditEvent source = makeAuditEvent(new Unknown(), null);
    assertThatThrownBy(() -> underTest.convert(source)).isInstanceOf(IllegalArgumentException.class);
}
Also used : ActorBase(com.sequenceiq.cloudbreak.audit.model.ActorBase) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 7 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method convertWithApiRequestData.

@Test
void convertWithApiRequestData() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    EventData eventData = ApiRequestData.builder().withApiVersion(API_VERSION).withMutating(MUTATING).withRequestParameters(REQUEST_PARAMETERS).withUserAgent(USER_AGENT).build();
    AuditEvent source = makeAuditEvent(actor, eventData);
    underTest = new AuditEventToGrpcAuditEventConverter(createMockUtilizer(ApiRequestData.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 8 with AuditEvent

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

the class AuditEventToGrpcAuditEventConverterTest method convertUnknownEventDataThrows.

@Test
void convertUnknownEventDataThrows() {
    ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
    class Unknown extends EventData {
    }
    AuditEvent source = makeAuditEvent(actor, new Unknown());
    assertThatThrownBy(() -> underTest.convert(source)).isInstanceOf(IllegalArgumentException.class);
}
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 9 with AuditEvent

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

the class AuditService method auditAutoscaleServiceEvent.

@Async
public void auditAutoscaleServiceEvent(ScalingStatus scalingStatus, String auditMessage, String clusterCrn, String accountId, Long timestamp) {
    AuditEvent event = null;
    try {
        Map<String, Object> eventDetails = new HashMap<>();
        eventDetails.put(CLUSTER_CRN, clusterCrn);
        eventDetails.put(TIMESTAMP, timestamp);
        eventDetails.put(AUTOSCALE_ACTION, auditMessage);
        eventDetails.put(AUTOSCALE_TRIGGER_STATUS, scalingStatus);
        ServiceEventData serviceEventData = ServiceEventData.builder().withEventDetails(new Json(eventDetails).getValue()).withVersion(periscopeVersion).build();
        event = AuditEvent.builder().withAccountId(accountId).withEventData(serviceEventData).withEventName(AuditEventName.AUTOSCALE_DATAHUB_CLUSTER).withEventSource(Crn.Service.DATAHUB).withActor(ActorService.builder().withActorServiceName(Crn.Service.DATAHUB.getName()).build()).build();
        auditClient.createAuditEvent(event);
    } catch (Exception ex) {
        LOGGER.warn("Service Audit event creation failed, error : '{}', event : '{}'", ex.getMessage(), event, ex);
    }
}
Also used : HashMap(java.util.HashMap) ServiceEventData(com.sequenceiq.cloudbreak.audit.model.ServiceEventData) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Json(com.sequenceiq.periscope.model.json.Json) Async(org.springframework.scheduling.annotation.Async)

Example 10 with AuditEvent

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

the class AuditServiceTest method testAuditRestEvent.

@Test
public void testAuditRestEvent() {
    Map requestParams = Map.of("param1", "param2");
    String userCrn = "crn:altus:iam:us-west-1:05681f13-41fc-4b2a-9588-a78d640f3c23:user:5f03bc0d-83d5-40c3-8624-f7b21481c1f7";
    underTest.auditRestApi(requestParams, true, "user-agent", userCrn, "user-account", "127.0.0.1");
    ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
    verify(auditClient, times(1)).createAuditEvent(captor.capture());
    AuditEvent auditEvent = captor.getValue();
    assertEquals("user-account", auditEvent.getAccountId());
    assertEquals("127.0.0.1", auditEvent.getSourceIp());
    assertEquals(MANAGE_AUTOSCALE_DATAHUB_CLUSTER, auditEvent.getEventName());
    assertEquals(Crn.Service.DATAHUB, auditEvent.getEventSource());
    assertEquals(userCrn, ((ActorCrn) auditEvent.getActor()).getActorCrn());
    ApiRequestData apiRequestData = (ApiRequestData) auditEvent.getEventData();
    assertEquals(new Gson().toJson(requestParams), apiRequestData.getRequestParameters());
    assertEquals("user-agent", apiRequestData.getUserAgent());
    assertEquals(true, apiRequestData.isMutating());
}
Also used : ApiRequestData(com.sequenceiq.cloudbreak.audit.model.ApiRequestData) Gson(com.google.gson.Gson) AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) Map(java.util.Map) Test(org.junit.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