Search in sources :

Example 1 with AuditApplicationEvent

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

the class AuthorizationAuditListenerTests method testAuthorizationFailure.

@Test
void testAuthorizationFailure() {
    AuditApplicationEvent event = handleAuthorizationEvent(new AuthorizationFailureEvent(this, Collections.singletonList(new SecurityConfig("USER")), new UsernamePasswordAuthenticationToken("user", "password"), new AccessDeniedException("Bad user")));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthorizationAuditListener.AUTHORIZATION_FAILURE);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecurityConfig(org.springframework.security.access.SecurityConfig) AuditApplicationEvent(org.springframework.boot.actuate.audit.listener.AuditApplicationEvent) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthorizationFailureEvent(org.springframework.security.access.event.AuthorizationFailureEvent) Test(org.junit.jupiter.api.Test)

Example 2 with AuditApplicationEvent

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

the class AuthorizationAuditListenerTests method testAuthenticationCredentialsNotFound.

@Test
void testAuthenticationCredentialsNotFound() {
    AuditApplicationEvent event = handleAuthorizationEvent(new AuthenticationCredentialsNotFoundEvent(this, Collections.singletonList(new SecurityConfig("USER")), new AuthenticationCredentialsNotFoundException("Bad user")));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthenticationAuditListener.AUTHENTICATION_FAILURE);
}
Also used : AuthenticationCredentialsNotFoundEvent(org.springframework.security.access.event.AuthenticationCredentialsNotFoundEvent) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) SecurityConfig(org.springframework.security.access.SecurityConfig) AuditApplicationEvent(org.springframework.boot.actuate.audit.listener.AuditApplicationEvent) Test(org.junit.jupiter.api.Test)

Example 3 with AuditApplicationEvent

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

the class AuthenticationAuditListenerTests method testDetailsAreIncludedInAuditEvent.

@Test
void testDetailsAreIncludedInAuditEvent() {
    Object details = new Object();
    UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("user", "password");
    authentication.setDetails(details);
    AuditApplicationEvent event = handleAuthenticationEvent(new AuthenticationFailureExpiredEvent(authentication, new BadCredentialsException("Bad user")));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthenticationAuditListener.AUTHENTICATION_FAILURE);
    assertThat(event.getAuditEvent().getData()).containsEntry("details", details);
}
Also used : AuditApplicationEvent(org.springframework.boot.actuate.audit.listener.AuditApplicationEvent) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) AuthenticationFailureExpiredEvent(org.springframework.security.authentication.event.AuthenticationFailureExpiredEvent) Test(org.junit.jupiter.api.Test)

Example 4 with AuditApplicationEvent

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

the class AuthenticationAuditListenerTests method testAuthenticationSwitchBackToAnonymous.

@Test
void testAuthenticationSwitchBackToAnonymous() {
    AuditApplicationEvent event = handleAuthenticationEvent(new AuthenticationSwitchUserEvent(new UsernamePasswordAuthenticationToken("user", "password"), null));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthenticationAuditListener.AUTHENTICATION_SWITCH);
}
Also used : AuditApplicationEvent(org.springframework.boot.actuate.audit.listener.AuditApplicationEvent) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AuthenticationSwitchUserEvent(org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent) Test(org.junit.jupiter.api.Test)

Example 5 with AuditApplicationEvent

use of org.springframework.boot.actuate.audit.listener.AuditApplicationEvent in project cas by apereo.

the class AbstractCasEventRepository method save.

@Override
public void save(final CasEvent event) throws Exception {
    if (getEventRepositoryFilter().shouldSaveEvent(event)) {
        saveInternal(event);
        if (applicationEventPublisher != null) {
            val auditEvent = new AuditEvent(event.getPrincipalId(), event.getType(), (Map) event.getProperties());
            applicationEventPublisher.publishEvent(new AuditApplicationEvent(auditEvent));
        }
    }
}
Also used : lombok.val(lombok.val) AuditApplicationEvent(org.springframework.boot.actuate.audit.listener.AuditApplicationEvent) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent)

Aggregations

AuditApplicationEvent (org.springframework.boot.actuate.audit.listener.AuditApplicationEvent)9 Test (org.junit.jupiter.api.Test)8 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 SecurityConfig (org.springframework.security.access.SecurityConfig)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 AuthorizationFailureEvent (org.springframework.security.access.event.AuthorizationFailureEvent)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)2 AuthenticationFailureExpiredEvent (org.springframework.security.authentication.event.AuthenticationFailureExpiredEvent)2 AuthenticationSwitchUserEvent (org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent)2 lombok.val (lombok.val)1 AuditEvent (org.springframework.boot.actuate.audit.AuditEvent)1 AuthenticationCredentialsNotFoundEvent (org.springframework.security.access.event.AuthenticationCredentialsNotFoundEvent)1 AuthenticationCredentialsNotFoundException (org.springframework.security.authentication.AuthenticationCredentialsNotFoundException)1 AuthenticationSuccessEvent (org.springframework.security.authentication.event.AuthenticationSuccessEvent)1 InteractiveAuthenticationSuccessEvent (org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent)1 User (org.springframework.security.core.userdetails.User)1