Improve MDCHolder method names (#1807)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -65,13 +65,13 @@ public class MDCHandler {
|
|||||||
|
|
||||||
final String currentTenant = MDC.get(MDC_KEY_TENANT);
|
final String currentTenant = MDC.get(MDC_KEY_TENANT);
|
||||||
if (Objects.equals(currentTenant, tenant)) {
|
if (Objects.equals(currentTenant, tenant)) {
|
||||||
return putUser(callable);
|
return putUserAndCall(callable);
|
||||||
} else {
|
} else {
|
||||||
set(MDC_KEY_TENANT, tenant);
|
put(MDC_KEY_TENANT, tenant);
|
||||||
try {
|
try {
|
||||||
return putUser(callable);
|
return putUserAndCall(callable);
|
||||||
} finally {
|
} finally {
|
||||||
set(MDC_KEY_TENANT, currentTenant);
|
put(MDC_KEY_TENANT, currentTenant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ public class MDCHandler {
|
|||||||
}, AuthorizationFilter.class);
|
}, AuthorizationFilter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T putUser(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()
|
||||||
.map(username -> (securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
|
.map(username -> (securityContext.isCurrentThreadSystemCode() ? "as " : "") + username)
|
||||||
@@ -122,11 +122,11 @@ public class MDCHandler {
|
|||||||
if (Objects.equals(currentUser, user)) {
|
if (Objects.equals(currentUser, user)) {
|
||||||
return callable.call();
|
return callable.call();
|
||||||
} else {
|
} else {
|
||||||
set(MDC_KEY_USER, user);
|
put(MDC_KEY_USER, user);
|
||||||
try {
|
try {
|
||||||
return callable.call();
|
return callable.call();
|
||||||
} finally {
|
} finally {
|
||||||
set(MDC_KEY_USER, currentUser);
|
put(MDC_KEY_USER, currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@@ -138,7 +138,7 @@ public class MDCHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void set(final String key, final String value) {
|
private static void put(final String key, final String value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
MDC.remove(key);
|
MDC.remove(key);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user