Restructure BasicAuthenticationFilter Logs

Issue gh-6311
This commit is contained in:
Eleftheria Stein-Kousathana 2020-09-01 08:23:58 -04:00 committed by Josh Cummings
parent fa7baf551d
commit 02d1516c56
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
1 changed files with 7 additions and 4 deletions

View File

@ -144,23 +144,26 @@ public class BasicAuthenticationFilter extends OncePerRequestFilter {
try { try {
UsernamePasswordAuthenticationToken authRequest = this.authenticationConverter.convert(request); UsernamePasswordAuthenticationToken authRequest = this.authenticationConverter.convert(request);
if (authRequest == null) { 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); chain.doFilter(request, response);
return; return;
} }
String username = authRequest.getName(); String username = authRequest.getName();
this.logger.debug( this.logger.trace(LogMessage.format("Found username '%s' in Basic Authorization header", username));
LogMessage.format("Basic Authentication Authorization header found for user '%s'", username));
if (authenticationIsRequired(username)) { if (authenticationIsRequired(username)) {
Authentication authResult = this.authenticationManager.authenticate(authRequest); Authentication authResult = this.authenticationManager.authenticate(authRequest);
this.logger.debug(LogMessage.format("Authentication success: %s", authResult));
SecurityContextHolder.getContext().setAuthentication(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); this.rememberMeServices.loginSuccess(request, response, authResult);
onSuccessfulAuthentication(request, response, authResult); onSuccessfulAuthentication(request, response, authResult);
} }
} }
catch (AuthenticationException ex) { catch (AuthenticationException ex) {
SecurityContextHolder.clearContext(); SecurityContextHolder.clearContext();
this.logger.debug("Authentication request for failed!", ex); this.logger.debug("Failed to process authentication request", ex);
this.rememberMeServices.loginFail(request, response); this.rememberMeServices.loginFail(request, response);
onUnsuccessfulAuthentication(request, response, ex); onUnsuccessfulAuthentication(request, response, ex);
if (this.ignoreFailure) { if (this.ignoreFailure) {