Search in sources :

Example 6 with AuditApplicationEvent

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

the class AuthenticationAuditListenerTests method testAuthenticationSwitch.

@Test
public void testAuthenticationSwitch() {
    AuditApplicationEvent event = handleAuthenticationEvent(new AuthenticationSwitchUserEvent(new UsernamePasswordAuthenticationToken("user", "password"), new User("user", "password", AuthorityUtils.commaSeparatedStringToAuthorityList("USER"))));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthenticationAuditListener.AUTHENTICATION_SWITCH);
}
Also used : User(org.springframework.security.core.userdetails.User) 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.Test)

Example 7 with AuditApplicationEvent

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

the class AuthorizationAuditListenerTests method testDetailsAreIncludedInAuditEvent.

@Test
public void testDetailsAreIncludedInAuditEvent() throws Exception {
    Object details = new Object();
    UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("user", "password");
    authentication.setDetails(details);
    AuditApplicationEvent event = handleAuthorizationEvent(new AuthorizationFailureEvent(this, Collections.<ConfigAttribute>singletonList(new SecurityConfig("USER")), authentication, new AccessDeniedException("Bad user")));
    assertThat(event.getAuditEvent().getType()).isEqualTo(AuthorizationAuditListener.AUTHORIZATION_FAILURE);
    assertThat(event.getAuditEvent().getData()).containsEntry("details", details);
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ConfigAttribute(org.springframework.security.access.ConfigAttribute) 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.Test)

Aggregations

Test (org.junit.Test)7 AuditApplicationEvent (org.springframework.boot.actuate.audit.listener.AuditApplicationEvent)7 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 ConfigAttribute (org.springframework.security.access.ConfigAttribute)3 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 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 AuthenticationSwitchUserEvent (org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent)1