Fix MDCHandler for servlets. Config enable -> enabled (#1808)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -36,7 +36,7 @@ public class MDCHandler {
|
|||||||
|
|
||||||
private static final MDCHandler SINGLETON = new MDCHandler();
|
private static final MDCHandler SINGLETON = new MDCHandler();
|
||||||
|
|
||||||
@Value("${hawkbit.logging.mdchandler.enable:true}")
|
@Value("${hawkbit.logging.mdchandler.enabled:true}")
|
||||||
private boolean mdcEnabled;
|
private boolean mdcEnabled;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SpringSecurityAuditorAware springSecurityAuditorAware;
|
private SpringSecurityAuditorAware springSecurityAuditorAware;
|
||||||
@@ -77,10 +77,6 @@ public class MDCHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addLoggingFilter(final HttpSecurity httpSecurity) {
|
public void addLoggingFilter(final HttpSecurity httpSecurity) {
|
||||||
if (!mdcEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
httpSecurity.addFilterBefore(new OncePerRequestFilter() {
|
httpSecurity.addFilterBefore(new OncePerRequestFilter() {
|
||||||
@Override
|
@Override
|
||||||
protected void doFilterInternal(
|
protected void doFilterInternal(
|
||||||
@@ -103,8 +99,7 @@ public class MDCHandler {
|
|||||||
throw we.toRuntimeException();
|
throw we.toRuntimeException();
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// should never be here - if mdc is handler is enabled non runtime exceptions are
|
// should never be here - if mdc is handler is enabled non-runtime exceptions are always wrapped
|
||||||
// always wrapped
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +109,7 @@ public class MDCHandler {
|
|||||||
private <T> T putUserAndCall(final Callable<T> callable) throws WrappedException {
|
private <T> T putUserAndCall(final Callable<T> callable) throws WrappedException {
|
||||||
final String user = springSecurityAuditorAware
|
final String user = springSecurityAuditorAware
|
||||||
.getCurrentAuditor()
|
.getCurrentAuditor()
|
||||||
|
.filter(username -> !username.equals("system")) // null and system are the same - system user
|
||||||
.map(username -> (securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
|
.map(username -> (securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user