@ -17,7 +17,6 @@
package org.springframework.boot.autoconfigure.security ;
package org.springframework.boot.autoconfigure.security ;
import java.util.List ;
import java.util.List ;
import java.util.concurrent.atomic.AtomicReference ;
import org.junit.After ;
import org.junit.After ;
import org.junit.Test ;
import org.junit.Test ;
@ -41,6 +40,7 @@ import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException ;
import org.springframework.security.authentication.BadCredentialsException ;
import org.springframework.security.authentication.TestingAuthenticationToken ;
import org.springframework.security.authentication.TestingAuthenticationToken ;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken ;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken ;
import org.springframework.security.authentication.event.AbstractAuthenticationEvent ;
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent ;
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent ;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder ;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder ;
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter ;
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter ;
@ -159,23 +159,22 @@ public class SecurityAutoConfigurationTests {
@Test
@Test
public void testEventPublisherInjected ( ) throws Exception {
public void testEventPublisherInjected ( ) throws Exception {
testAuthenticationManagerCreated ( ) ;
testAuthenticationManagerCreated ( ) ;
final AtomicReference < ApplicationEvent > wrapper = new AtomicReference < ApplicationEvent > ( ) ;
pingAuthenticationListener ( ) ;
this . context . addApplicationListener ( new ApplicationListener < ApplicationEvent > ( ) {
}
@Override
public void onApplicationEvent ( ApplicationEvent event ) {
private void pingAuthenticationListener ( ) {
wrapper . set ( event ) ;
AuthenticationListener listener = new AuthenticationListener ( ) ;
} ;
this . context . addApplicationListener ( listener ) ;
} ) ;
AuthenticationManager manager = this . context . getBean ( AuthenticationManager . class ) ;
AuthenticationManager manager = this . context . getBean ( AuthenticationManager . class ) ;
try {
try {
manager . authenticate ( new UsernamePasswordAuthenticationToken ( "foo" , " bar ") ) ;
manager . authenticate ( new UsernamePasswordAuthenticationToken ( "foo" , " wrong ") ) ;
fail ( "Expected BadCredentialsException" ) ;
fail ( "Expected BadCredentialsException" ) ;
}
}
catch ( BadCredentialsException e ) {
catch ( BadCredentialsException e ) {
// expected
// expected
}
}
assertTrue ( "Wrong event type: " + wrapper. get ( ) ,
assertTrue ( "Wrong event type: " + listener. event ,
wrapper. get ( ) instanceof AuthenticationFailureBadCredentialsEvent ) ;
listener. event instanceof AuthenticationFailureBadCredentialsEvent ) ;
}
}
@Test
@Test
@ -221,6 +220,7 @@ public class SecurityAutoConfigurationTests {
AuthorityUtils . commaSeparatedStringToAuthorityList ( "ROLE_USER" ) ) ;
AuthorityUtils . commaSeparatedStringToAuthorityList ( "ROLE_USER" ) ) ;
assertNotNull ( this . context . getBean ( AuthenticationManager . class )
assertNotNull ( this . context . getBean ( AuthenticationManager . class )
. authenticate ( user ) ) ;
. authenticate ( user ) ) ;
pingAuthenticationListener ( ) ;
}
}
@Test
@Test
@ -256,6 +256,17 @@ public class SecurityAutoConfigurationTests {
assertNotNull ( this . context . getBean ( JpaTransactionManager . class ) ) ;
assertNotNull ( this . context . getBean ( JpaTransactionManager . class ) ) ;
}
}
private static final class AuthenticationListener implements
ApplicationListener < AbstractAuthenticationEvent > {
private ApplicationEvent event ;
@Override
public void onApplicationEvent ( AbstractAuthenticationEvent event ) {
this . event = event ;
}
}
@Configuration
@Configuration
@TestAutoConfigurationPackage ( City . class )
@TestAutoConfigurationPackage ( City . class )
protected static class EntityConfiguration {
protected static class EntityConfiguration {