Search in sources :

Example 6 with PersistentAuditEvent

use of com.arnaugarcia.uplace.domain.PersistentAuditEvent in project uplace.es by Uplace.

the class AuditResourceIntTest method initTest.

@Before
public void initTest() {
    auditEventRepository.deleteAll();
    auditEvent = new PersistentAuditEvent();
    auditEvent.setAuditEventType(SAMPLE_TYPE);
    auditEvent.setPrincipal(SAMPLE_PRINCIPAL);
    auditEvent.setAuditEventDate(SAMPLE_TIMESTAMP);
}
Also used : PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) Before(org.junit.Before)

Example 7 with PersistentAuditEvent

use of com.arnaugarcia.uplace.domain.PersistentAuditEvent in project uplace.es by Uplace.

the class CustomAuditEventRepository method add.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void add(AuditEvent event) {
    if (!AUTHORIZATION_FAILURE.equals(event.getType()) && !Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {
        PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
        persistentAuditEvent.setPrincipal(event.getPrincipal());
        persistentAuditEvent.setAuditEventType(event.getType());
        persistentAuditEvent.setAuditEventDate(event.getTimestamp().toInstant());
        Map<String, String> eventData = auditEventConverter.convertDataToStrings(event.getData());
        persistentAuditEvent.setData(truncate(eventData));
        persistenceAuditEventRepository.save(persistentAuditEvent);
    }
}
Also used : PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with PersistentAuditEvent

use of com.arnaugarcia.uplace.domain.PersistentAuditEvent in project uplace.es by Uplace.

the class CustomAuditEventRepositoryIntTest method addAuditEventWithAuthorizationFailureType.

@Test
public void addAuditEventWithAuthorizationFailureType() {
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", "test-value");
    AuditEvent event = new AuditEvent("test-user", "AUTHORIZATION_FAILURE", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(0);
}
Also used : PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) HashMap(java.util.HashMap) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with PersistentAuditEvent

use of com.arnaugarcia.uplace.domain.PersistentAuditEvent in project uplace.es by Uplace.

the class CustomAuditEventRepositoryIntTest method addAuditEventTruncateLargeData.

@Test
public void addAuditEventTruncateLargeData() {
    Map<String, Object> data = new HashMap<>();
    StringBuilder largeData = new StringBuilder();
    for (int i = 0; i < EVENT_DATA_COLUMN_MAX_LENGTH + 10; i++) {
        largeData.append("a");
    }
    data.put("test-key", largeData);
    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");
    String actualData = persistentAuditEvent.getData().get("test-key");
    assertThat(actualData.length()).isEqualTo(EVENT_DATA_COLUMN_MAX_LENGTH);
    assertThat(actualData).isSubstringOf(largeData);
    assertThat(persistentAuditEvent.getAuditEventDate()).isEqualTo(event.getTimestamp().toInstant());
}
Also used : PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) HashMap(java.util.HashMap) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with PersistentAuditEvent

use of com.arnaugarcia.uplace.domain.PersistentAuditEvent 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());
}
Also used : PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) HashMap(java.util.HashMap) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) PersistentAuditEvent(com.arnaugarcia.uplace.domain.PersistentAuditEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PersistentAuditEvent (com.arnaugarcia.uplace.domain.PersistentAuditEvent)10 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 AuditEvent (org.springframework.boot.actuate.audit.AuditEvent)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Before (org.junit.Before)2 Instant (java.time.Instant)1 HttpSession (javax.servlet.http.HttpSession)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)1 Transactional (org.springframework.transaction.annotation.Transactional)1