use of org.springframework.boot.actuate.audit.AuditEvent in project uplace.es by Uplace.
the class CustomAuditEventRepositoryIntTest method addAuditEvent.
@Test
public void addAuditEvent() {
Map<String, Object> data = new HashMap<>();
data.put("test-key", "test-value");
AuditEvent event = new AuditEvent("test-user", "test-type", data);
customAuditEventRepository.add(event);
List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
assertThat(persistentAuditEvents).hasSize(1);
PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
assertThat(persistentAuditEvent.getPrincipal()).isEqualTo(event.getPrincipal());
assertThat(persistentAuditEvent.getAuditEventType()).isEqualTo(event.getType());
assertThat(persistentAuditEvent.getData()).containsKey("test-key");
assertThat(persistentAuditEvent.getData().get("test-key")).isEqualTo("test-value");
assertThat(persistentAuditEvent.getAuditEventDate()).isEqualTo(event.getTimestamp().toInstant());
}
use of org.springframework.boot.actuate.audit.AuditEvent in project uplace.es by Uplace.
the class CustomAuditEventRepositoryIntTest method testFindAfter.
@Test
public void testFindAfter() {
persistenceAuditEventRepository.save(testUserEvent);
persistenceAuditEventRepository.save(testOldUserEvent);
List<AuditEvent> events = customAuditEventRepository.find(Date.from(testUserEvent.getAuditEventDate().minusSeconds(3600)));
assertThat(events).hasSize(1);
AuditEvent event = events.get(0);
assertThat(event.getPrincipal()).isEqualTo(testUserEvent.getPrincipal());
assertThat(event.getType()).isEqualTo(testUserEvent.getAuditEventType());
assertThat(event.getData()).containsKey("test-key");
assertThat(event.getData().get("test-key").toString()).isEqualTo("test-value");
assertThat(event.getTimestamp()).isEqualTo(Date.from(testUserEvent.getAuditEventDate()));
}
use of org.springframework.boot.actuate.audit.AuditEvent in project zhcet-web by zhcet-amu.
the class PathAuthorizationAuditListener method onAuthorizationFailureEvent.
private void onAuthorizationFailureEvent(AuthorizationFailureEvent event) {
Map<String, Object> data = new HashMap<>();
data.put("authorities", event.getAuthentication().getAuthorities());
data.put("type", event.getAccessDeniedException().getClass().getName());
data.put("message", event.getAccessDeniedException().getMessage());
if (event.getSource() instanceof FilterInvocation)
data.put("requestUrl", ((FilterInvocation) event.getSource()).getRequestUrl());
else if (event.getSource() instanceof ReflectiveMethodInvocation)
data.put("source", event.getSource());
if (event.getAuthentication().getDetails() != null) {
data.put("details", event.getAuthentication().getDetails());
}
publish(new AuditEvent(event.getAuthentication().getName(), AuthorizationAuditListener.AUTHORIZATION_FAILURE, data));
}
use of org.springframework.boot.actuate.audit.AuditEvent in project zhcet-web by zhcet-amu.
the class PathAuthorizationAuditListener method onAuthenticationCredentialsNotFoundEvent.
private void onAuthenticationCredentialsNotFoundEvent(AuthenticationCredentialsNotFoundEvent event) {
Map<String, Object> data = new HashMap<>();
data.put("type", event.getCredentialsNotFoundException().getClass().getName());
data.put("message", event.getCredentialsNotFoundException().getMessage());
if (event.getSource() instanceof FilterInvocation)
data.put("requestUrl", ((FilterInvocation) event.getSource()).getRequestUrl());
else if (event.getSource() instanceof ReflectiveMethodInvocation)
data.put("source", event.getSource());
publish(new AuditEvent("<unknown>", AuthenticationAuditListener.AUTHENTICATION_FAILURE, data));
}
Aggregations