@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 2015 the original author or authors .
* Copyright 2012 - 2016 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,7 +18,9 @@ package org.springframework.boot.actuate.security;
@@ -18,7 +18,9 @@ package org.springframework.boot.actuate.security;
import org.junit.Before ;
import org.junit.Test ;
import org.mockito.ArgumentCaptor ;
import org.springframework.boot.actuate.audit.listener.AuditApplicationEvent ;
import org.springframework.context.ApplicationEvent ;
import org.springframework.context.ApplicationEventPublisher ;
import org.springframework.security.authentication.BadCredentialsException ;
@ -30,6 +32,8 @@ import org.springframework.security.core.authority.AuthorityUtils;
@@ -30,6 +32,8 @@ import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User ;
import org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent ;
import static org.hamcrest.Matchers.hasEntry ;
import static org.junit.Assert.assertThat ;
import static org.mockito.Matchers.anyObject ;
import static org.mockito.Mockito.mock ;
import static org.mockito.Mockito.never ;
@ -82,4 +86,18 @@ public class AuthenticationAuditListenerTests {
@@ -82,4 +86,18 @@ public class AuthenticationAuditListenerTests {
verify ( this . publisher ) . publishEvent ( ( ApplicationEvent ) anyObject ( ) ) ;
}
@Test
public void testDetailsAreIncludedInAuditEvent ( ) throws Exception {
Object details = new Object ( ) ;
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken (
"user" , "password" ) ;
authentication . setDetails ( details ) ;
this . listener . onApplicationEvent ( new AuthenticationFailureExpiredEvent (
authentication , new BadCredentialsException ( "Bad user" ) ) ) ;
ArgumentCaptor < AuditApplicationEvent > auditApplicationEvent = ArgumentCaptor
. forClass ( AuditApplicationEvent . class ) ;
verify ( this . publisher ) . publishEvent ( auditApplicationEvent . capture ( ) ) ;
assertThat ( auditApplicationEvent . getValue ( ) . getAuditEvent ( ) . getData ( ) ,
hasEntry ( "details" , details ) ) ;
}
}