Skip to content

Commit

Permalink
Fix MDCHandler for servlets. Config enable -> enabled (#1808)
Browse files Browse the repository at this point in the history
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm authored Aug 9, 2024
1 parent 141d167 commit 9dd493d
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MDCHandler {

private static final MDCHandler SINGLETON = new MDCHandler();

@Value("${hawkbit.logging.mdchandler.enable:true}")
@Value("${hawkbit.logging.mdchandler.enabled:true}")
private boolean mdcEnabled;
@Autowired
private SpringSecurityAuditorAware springSecurityAuditorAware;
Expand Down Expand Up @@ -77,10 +77,6 @@ public <T> T withLogging(final Callable<T> callable) throws Exception {
}

public void addLoggingFilter(final HttpSecurity httpSecurity) {
if (!mdcEnabled) {
return;
}

httpSecurity.addFilterBefore(new OncePerRequestFilter() {
@Override
protected void doFilterInternal(
Expand All @@ -103,8 +99,7 @@ protected void doFilterInternal(
throw we.toRuntimeException();
}
} catch (final Exception e) {
// should never be here - if mdc is handler is enabled non runtime exceptions are
// always wrapped
// should never be here - if mdc is handler is enabled non-runtime exceptions are always wrapped
throw new RuntimeException(e);
}
}
Expand All @@ -114,6 +109,7 @@ protected void doFilterInternal(
private <T> T putUserAndCall(final Callable<T> callable) throws WrappedException {
final String user = springSecurityAuditorAware
.getCurrentAuditor()
.filter(username -> !username.equals("system")) // null and system are the same - system user
.map(username -> (securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
.orElse(null);

Expand Down

0 comments on commit 9dd493d

Please sign in to comment.