Skip to content

Commit 7341882

Browse files
committed
SEC-1940: ProviderManager publishes any AccountStatusException
Previously there was a bug introduced by SEC-546 that prevented any AccountStatusException from being published. Now AccountStatusExceptions are also published.
1 parent a057241 commit 7341882

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

core/src/main/java/org/springframework/security/authentication/ProviderManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {

core/src/test/java/org/springframework/security/authentication/ProviderManagerTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)