Search in sources :

Example 6 with AuditEvent

use of org.springframework.boot.actuate.audit.AuditEvent in project uplace.es by Uplace.

the class AuditResource method getAll.

/**
 * GET /audits : get a page of AuditEvents.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 */
@GetMapping
public ResponseEntity<List<AuditEvent>> getAll(Pageable pageable) {
    Page<AuditEvent> page = auditEventService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent)

Example 7 with AuditEvent

use of org.springframework.boot.actuate.audit.AuditEvent in project zhcet-web by zhcet-amu.

the class LoginAttemptListener method auditEventHappened.

@EventListener
public void auditEventHappened(AuditApplicationEvent auditApplicationEvent) {
    AuditEvent auditEvent = auditApplicationEvent.getAuditEvent();
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Principal ").append(auditEvent.getPrincipal()).append(" - ").append(auditEvent.getType());
    stringBuilder.append("\n  Authorities: ").append(auditEvent.getData().get("authorities"));
    WebAuthenticationDetails details = (WebAuthenticationDetails) auditEvent.getData().get("details");
    loginAttemptService.loginAttempt(auditEvent, details);
    if (details != null) {
        stringBuilder.append("\n  Remote IP address: ").append(details.getRemoteAddress());
        stringBuilder.append("\n  Session ID: ").append(details.getSessionId());
    }
    stringBuilder.append("\n  Request URL: ").append(auditEvent.getData().get("requestUrl"));
    stringBuilder.append("\n  Source: ").append(auditEvent.getData().get("source"));
    String message = stringBuilder.toString();
    if (auditEvent.getType().equals(AuthenticationAuditListener.AUTHENTICATION_FAILURE)) {
        log.warn(message);
    } else {
        log.info(message);
    }
}
Also used : WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) EventListener(org.springframework.context.event.EventListener)

Example 8 with AuditEvent

use of org.springframework.boot.actuate.audit.AuditEvent in project spring-boot by spring-projects.

the class AuthenticationAuditListener method onAuthenticationFailureEvent.

private void onAuthenticationFailureEvent(AbstractAuthenticationFailureEvent event) {
    Map<String, Object> data = new HashMap<>();
    data.put("type", event.getException().getClass().getName());
    data.put("message", event.getException().getMessage());
    if (event.getAuthentication().getDetails() != null) {
        data.put("details", event.getAuthentication().getDetails());
    }
    publish(new AuditEvent(event.getAuthentication().getName(), AUTHENTICATION_FAILURE, data));
}
Also used : HashMap(java.util.HashMap) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent)

Example 9 with AuditEvent

use of org.springframework.boot.actuate.audit.AuditEvent in project spring-boot by spring-projects.

the class AuthenticationAuditListener method onAuthenticationSuccessEvent.

private void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
    Map<String, Object> data = new HashMap<>();
    if (event.getAuthentication().getDetails() != null) {
        data.put("details", event.getAuthentication().getDetails());
    }
    publish(new AuditEvent(event.getAuthentication().getName(), AUTHENTICATION_SUCCESS, data));
}
Also used : HashMap(java.util.HashMap) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent)

Example 10 with AuditEvent

use of org.springframework.boot.actuate.audit.AuditEvent in project spring-boot by spring-projects.

the class AuthorizationAuditListener method onAuthorizationFailureEvent.

private void onAuthorizationFailureEvent(AuthorizationFailureEvent event) {
    Map<String, Object> data = new HashMap<>();
    data.put("type", event.getAccessDeniedException().getClass().getName());
    data.put("message", event.getAccessDeniedException().getMessage());
    if (event.getAuthentication().getDetails() != null) {
        data.put("details", event.getAuthentication().getDetails());
    }
    publish(new AuditEvent(event.getAuthentication().getName(), AUTHORIZATION_FAILURE, data));
}
Also used : HashMap(java.util.HashMap) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent)

Aggregations

AuditEvent (org.springframework.boot.actuate.audit.AuditEvent)19 HashMap (java.util.HashMap)12 Test (org.junit.Test)10 PersistentAuditEvent (com.arnaugarcia.uplace.domain.PersistentAuditEvent)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ReflectiveMethodInvocation (org.springframework.aop.framework.ReflectiveMethodInvocation)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 FilterInvocation (org.springframework.security.web.FilterInvocation)2 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)2 HttpSession (javax.servlet.http.HttpSession)1 AuditEventRepository (org.springframework.boot.actuate.audit.AuditEventRepository)1 EventListener (org.springframework.context.event.EventListener)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1