Skip to content

Commit b9ed086

Browse files
committed
Add debug messages for auth exceptions in ProviderManager
Signed-off-by: tejas-teju <[email protected]>
1 parent ab10b98 commit b9ed086

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,25 @@ public Authentication authenticate(Authentication authentication) throws Authent
185185
break;
186186
}
187187
}
188-
catch (AccountStatusException | InternalAuthenticationServiceException ex) {
188+
catch (AccountStatusException ex) {
189189
prepareException(ex, authentication);
190+
logger.debug(LogMessage.format("Authentication failed for user '%s' since account status is %s",
191+
authentication.getName(), ex.getMessage()));
192+
// SEC-546: Avoid polling additional providers if auth failure is due to
193+
// invalid account status
194+
throw ex;
195+
}
196+
catch (InternalAuthenticationServiceException ex) {
197+
prepareException(ex, authentication);
198+
logger.debug(LogMessage.format(
199+
"Authentication failed due to an internal authentication service error: %s", ex.getMessage()));
190200
// SEC-546: Avoid polling additional providers if auth failure is due to
191201
// invalid account status
192202
throw ex;
193203
}
194204
catch (AuthenticationException ex) {
205+
logger.debug(LogMessage.format("Authentication failed with provider %s since %s",
206+
provider.getClass().getSimpleName(), ex.getMessage()));
195207
lastException = ex;
196208
}
197209
}
@@ -241,6 +253,13 @@ public Authentication authenticate(Authentication authentication) throws Authent
241253
if (parentException == null) {
242254
prepareException(lastException, authentication);
243255
}
256+
257+
// Ensure this message is not logged when authentication is attempted by
258+
// the parent provider
259+
if (this.parent != null) {
260+
logger.debug("Denying authentication since all attempted providers failed");
261+
}
262+
244263
throw lastException;
245264
}
246265

0 commit comments

Comments
 (0)