File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/org/springframework/security/authentication
test/java/org/springframework/security/authentication Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -197,14 +197,14 @@ public Authentication authenticate(Authentication authentication) throws Authent
197197 new Object [] {toTest .getName ()}, "No AuthenticationProvider found for {0}" ));
198198 }
199199
200- eventPublisher .publishAuthenticationFailure (lastException , authentication );
201200 prepareException (lastException , authentication );
202201
203202 throw lastException ;
204203 }
205204
206205 @ SuppressWarnings ("deprecation" )
207206 private void prepareException (AuthenticationException ex , Authentication auth ) {
207+ eventPublisher .publishAuthenticationFailure (ex , auth );
208208 ex .setAuthentication (auth );
209209
210210 if (clearExtraInformation ) {
Original file line number Diff line number Diff line change @@ -267,6 +267,26 @@ public void authenticationExceptionFromParentOverridesPreviousOnes() throws Exce
267267 verify (publisher ).publishAuthenticationFailure (expected , authReq );
268268 }
269269
270+ @ Test
271+ @ SuppressWarnings ("deprecation" )
272+ public void statusExceptionIsPublished () throws Exception {
273+ AuthenticationManager parent = mock (AuthenticationManager .class );
274+ final LockedException expected = new LockedException ("" );
275+ ProviderManager mgr = new ProviderManager (
276+ Arrays .asList (createProviderWhichThrows (expected )), parent );
277+ final Authentication authReq = mock (Authentication .class );
278+ AuthenticationEventPublisher publisher = mock (AuthenticationEventPublisher .class );
279+ mgr .setAuthenticationEventPublisher (publisher );
280+ try {
281+ mgr .authenticate (authReq );
282+ fail ("Expected exception" );
283+ } catch (LockedException e ) {
284+ assertSame (expected , e );
285+ assertSame (authReq , e .getAuthentication ());
286+ }
287+ verify (publisher ).publishAuthenticationFailure (expected , authReq );
288+ }
289+
270290 private AuthenticationProvider createProviderWhichThrows (final AuthenticationException e ) {
271291 AuthenticationProvider provider = mock (AuthenticationProvider .class );
272292 when (provider .supports (any (Class .class ))).thenReturn (true );
You can’t perform that action at this time.
0 commit comments