Search in sources :

Example 1 with ApiRequestData

use of com.sequenceiq.cloudbreak.audit.model.ApiRequestData 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)

Example 2 with ApiRequestData

use of com.sequenceiq.cloudbreak.audit.model.ApiRequestData 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

ApiRequestData (com.sequenceiq.cloudbreak.audit.model.ApiRequestData)2 AuditEvent (com.sequenceiq.cloudbreak.audit.model.AuditEvent)2 Gson (com.google.gson.Gson)1 Json (com.sequenceiq.periscope.model.json.Json)1 Map (java.util.Map)1 Test (org.junit.Test)1 Async (org.springframework.scheduling.annotation.Async)1