Skip to content

Commit 02d1516

Browse files
eleftheriasjzheaux
authored andcommitted
Restructure BasicAuthenticationFilter Logs
Issue gh-6311
1 parent fa7baf5 commit 02d1516

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,26 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
144144
try {
145145
UsernamePasswordAuthenticationToken authRequest = this.authenticationConverter.convert(request);
146146
if (authRequest == null) {
147+
this.logger.trace("Did not process authentication request since failed to find "
148+
+ "username and password in Basic Authorization header");
147149
chain.doFilter(request, response);
148150
return;
149151
}
150152
String username = authRequest.getName();
151-
this.logger.debug(
152-
LogMessage.format("Basic Authentication Authorization header found for user '%s'", username));
153+
this.logger.trace(LogMessage.format("Found username '%s' in Basic Authorization header", username));
153154
if (authenticationIsRequired(username)) {
154155
Authentication authResult = this.authenticationManager.authenticate(authRequest);
155-
this.logger.debug(LogMessage.format("Authentication success: %s", authResult));
156156
SecurityContextHolder.getContext().setAuthentication(authResult);
157+
if (this.logger.isDebugEnabled()) {
158+
this.logger.debug(LogMessage.format("Set SecurityContextHolder to %s", authResult));
159+
}
157160
this.rememberMeServices.loginSuccess(request, response, authResult);
158161
onSuccessfulAuthentication(request, response, authResult);
159162
}
160163
}
161164
catch (AuthenticationException ex) {
162165
SecurityContextHolder.clearContext();
163-
this.logger.debug("Authentication request for failed!", ex);
166+
this.logger.debug("Failed to process authentication request", ex);
164167
this.rememberMeServices.loginFail(request, response);
165168
onUnsuccessfulAuthentication(request, response, ex);
166169
if (this.ignoreFailure) {

0 commit comments

Comments
 (0)