diff --git a/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java b/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java index 263a5dee193ee08e82e57552f7ab8d5bdb8f99e0..b4af079cea76d62aa1686e0562bf8a2e5d6ad6a8 100644 --- a/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java +++ b/src/main/java/neatlogic/framework/asynchronization/threadlocal/UserContext.java @@ -27,6 +27,7 @@ import neatlogic.framework.exception.user.NoUserException; import neatlogic.framework.filter.core.LoginAuthHandlerBase; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.slf4j.MDC; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -80,6 +81,7 @@ public class UserContext implements Serializable { context = _userContext.copy(); } instance.set(context); + MDC.put("userId", context.getUserId()); return context; } @@ -102,6 +104,7 @@ public class UserContext implements Serializable { } context.setAuthenticationInfoVo(new AuthenticationInfoVo(context.getUserUuid(), new ArrayList<>(), roleUuidList, new HashSet<>(), null)); instance.set(context); + MDC.put("userId", context.getUserId()); return context; } @@ -130,6 +133,7 @@ public class UserContext implements Serializable { } context.setJwtVo(userVo.getJwtVo()); instance.set(context); + MDC.put("userId", context.getUserId()); return context; } diff --git a/src/main/java/neatlogic/framework/logback/converter/TenantConverter.java b/src/main/java/neatlogic/framework/logback/converter/TenantConverter.java index c0efe54bdcf50ed18e4d449e9746890a610345de..482352485af151d448eca95cdb8d722ab588a73b 100644 --- a/src/main/java/neatlogic/framework/logback/converter/TenantConverter.java +++ b/src/main/java/neatlogic/framework/logback/converter/TenantConverter.java @@ -40,6 +40,10 @@ public class TenantConverter extends ClassicConverter implements Serializable { Map map = event.getMDCPropertyMap(); String tenant = map.get("tenant"); if (StringUtils.isNotBlank(tenant)) { + String userId = map.get("userId"); + if (StringUtils.isNotBlank(userId)) { + tenant += "(" + userId + ")"; + } return tenant; } return StringUtils.EMPTY; diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java index b96fe0f87d00f753f3f0cb424d8f4075eaaafba7..984d1cef0b20286d7df3cc7b1be58dab8d033d6f 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java @@ -81,6 +81,11 @@ public class AnonymousApiDispatcher { private ApiAccessCountService apiAccessCountService; private void doIt(HttpServletRequest request, HttpServletResponse response, String token, boolean tokenHasEncrypted, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { + UserContext userContext = UserContext.get(); + if (userContext != null) { + request.setAttribute("userId", userContext.getUserId()); + request.setAttribute("userName", userContext.getUserName()); + } InputFrom inputFrom = null; String source = request.getHeader("source"); if (StringUtils.isNotBlank(source)) { diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java index a09a0aa0b640e5acde430ccd43b91fde01efce33..5b5358e0f033460d2e4800a1a7266c93cf800981 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java @@ -98,6 +98,11 @@ public class ApiDispatcher { private void doIt(HttpServletRequest request, HttpServletResponse response, String token, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { + UserContext userContext = UserContext.get(); + if (userContext != null) { + request.setAttribute("userId", userContext.getUserId()); + request.setAttribute("userName", userContext.getUserName()); + } InputFrom inputFrom = null; String source = request.getHeader("source"); if (StringUtils.isNotBlank(source)) { diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java index 306a37714435c8c20fbf205b2acbaa366a14c1aa..0abbdd4147d1680b71e327ae97570768df6a6de3 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java @@ -48,7 +48,6 @@ import neatlogic.framework.restful.enums.ApiType; import neatlogic.framework.restful.ratelimiter.RateLimiterTokenBucket; import neatlogic.framework.service.AuthenticationInfoService; import neatlogic.module.framework.restful.counter.ApiAccessCountService; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; @@ -91,6 +90,11 @@ public class PublicApiDispatcher { private void doIt(HttpServletRequest request, HttpServletResponse response, String token, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { + UserContext userContext = UserContext.get(); + if (userContext != null) { + request.setAttribute("userId", userContext.getUserId()); + request.setAttribute("userName", userContext.getUserName()); + } InputFrom inputFrom = null; String source = request.getHeader("source"); if (StringUtils.isNotBlank(source)) {