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 {
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) {