Skip to content

Commit

Permalink
Feature/remove hard requirements for mdc (#1811)
Browse files Browse the repository at this point in the history
* Remove hard requirements for MDCHandler dependencies

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

---------

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm authored Aug 9, 2024
1 parent 8c2d103 commit e874cf5
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class MDCHandler {

@Value("${hawkbit.logging.mdchandler.enabled:true}")
private boolean mdcEnabled;
@Autowired
private SpringSecurityAuditorAware springSecurityAuditorAware;
@Autowired
@Autowired(required = false)
private SpringSecurityAuditorAware springSecurityAuditorAware = new SpringSecurityAuditorAware();
@Autowired(required = false)
private SystemSecurityContext securityContext;

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ 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)
.map(username -> (securityContext != null && securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
.orElse(null);

final String currentUser = MDC.get(MDC_KEY_USER);
Expand Down

0 comments on commit e874cf5

Please sign in to comment.