Search in sources :

Example 1 with AuthenticationFailureExpiredEvent

use of org.springframework.security.authentication.event.AuthenticationFailureExpiredEvent 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 2 with AuthenticationFailureExpiredEvent

use of org.springframework.security.authentication.event.AuthenticationFailureExpiredEvent in project spring-boot by spring-projects.

the class AuthenticationAuditListenerTests method testAuthenticationFailed.

@Test
void testAuthenticationFailed() {
    AuditApplicationEvent event = handleAuthenticationEvent(new AuthenticationFailureExpiredEvent(new UsernamePasswordAuthenticationToken("user", "password"), new BadCredentialsException("Bad user")));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthenticationAuditListener.AUTHENTICATION_FAILURE);
}
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)

Aggregations

Test (org.junit.jupiter.api.Test)2 AuditApplicationEvent (org.springframework.boot.actuate.audit.listener.AuditApplicationEvent)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 AuthenticationFailureExpiredEvent (org.springframework.security.authentication.event.AuthenticationFailureExpiredEvent)2