From 02d1516c566a58574af0a1d0391fd2ec8c5ad774 Mon Sep 17 00:00:00 2001 From: Eleftheria Stein-Kousathana Date: Tue, 1 Sep 2020 08:23:58 -0400 Subject: [PATCH] Restructure BasicAuthenticationFilter Logs Issue gh-6311 --- .../authentication/www/BasicAuthenticationFilter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java b/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java index 199eb1d429..e744825b4e 100644 --- a/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java +++ b/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java @@ -144,23 +144,26 @@ public class BasicAuthenticationFilter extends OncePerRequestFilter { try { UsernamePasswordAuthenticationToken authRequest = this.authenticationConverter.convert(request); if (authRequest == null) { + this.logger.trace("Did not process authentication request since failed to find " + + "username and password in Basic Authorization header"); chain.doFilter(request, response); return; } String username = authRequest.getName(); - this.logger.debug( - LogMessage.format("Basic Authentication Authorization header found for user '%s'", username)); + this.logger.trace(LogMessage.format("Found username '%s' in Basic Authorization header", username)); if (authenticationIsRequired(username)) { Authentication authResult = this.authenticationManager.authenticate(authRequest); - this.logger.debug(LogMessage.format("Authentication success: %s", authResult)); SecurityContextHolder.getContext().setAuthentication(authResult); + if (this.logger.isDebugEnabled()) { + this.logger.debug(LogMessage.format("Set SecurityContextHolder to %s", authResult)); + } this.rememberMeServices.loginSuccess(request, response, authResult); onSuccessfulAuthentication(request, response, authResult); } } catch (AuthenticationException ex) { SecurityContextHolder.clearContext(); - this.logger.debug("Authentication request for failed!", ex); + this.logger.debug("Failed to process authentication request", ex); this.rememberMeServices.loginFail(request, response); onUnsuccessfulAuthentication(request, response, ex); if (this.ignoreFailure) {