Feature/remove hard requirements for mdc (#1811)

* Remove hard requirements for MDCHandler dependencies

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>

---------

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-08-09 18:12:58 +03:00
committed by GitHub
parent 8c2d1037bb
commit e874cf5014

View File

@@ -38,9 +38,9 @@ public class MDCHandler {
@Value("${hawkbit.logging.mdchandler.enabled:true}") @Value("${hawkbit.logging.mdchandler.enabled:true}")
private boolean mdcEnabled; private boolean mdcEnabled;
@Autowired @Autowired(required = false)
private SpringSecurityAuditorAware springSecurityAuditorAware; private SpringSecurityAuditorAware springSecurityAuditorAware = new SpringSecurityAuditorAware();
@Autowired @Autowired(required = false)
private SystemSecurityContext securityContext; private SystemSecurityContext securityContext;
/** /**
@@ -110,7 +110,7 @@ public class MDCHandler {
final String user = springSecurityAuditorAware final String user = springSecurityAuditorAware
.getCurrentAuditor() .getCurrentAuditor()
.filter(username -> !username.equals("system")) // null and system are the same - system user .filter(username -> !username.equals("system")) // null and system are the same - system user
.map(username -> (securityContext.isCurrentThreadSystemCode() ? "as " : "") + username) .map(username -> (securityContext != null && securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
.orElse(null); .orElse(null);
final String currentUser = MDC.get(MDC_KEY_USER); final String currentUser = MDC.get(MDC_KEY_USER);