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());
}
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);
}
}
Aggregations