diff --git a/backend/src/main/java/io/metersphere/controller/LoginController.java b/backend/src/main/java/io/metersphere/controller/LoginController.java index 25d28015b5..6481280ff2 100644 --- a/backend/src/main/java/io/metersphere/controller/LoginController.java +++ b/backend/src/main/java/io/metersphere/controller/LoginController.java @@ -64,7 +64,7 @@ public class LoginController { } @GetMapping(value = "/signout") - @MsAuditLog(module = "auth_title", type = OperLogConstants.LOGIN, title = "登出") + @MsAuditLog(module = "auth_title", beforeEvent = "#msClass.getUserId(id)",type = OperLogConstants.LOGIN, title = "登出",msClass = SessionUtils.class) public ResultHolder logout() throws Exception { userService.logout(); SecurityUtils.getSubject().logout(); diff --git a/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java b/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java index 976395b50e..f454dc3a0a 100644 --- a/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java +++ b/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java @@ -86,25 +86,26 @@ public class MsLogAspect { for (int len = 0; len < params.length; len++) { context.setVariable(params[len], args[len]); } + InvocationHandler invocationHandler = Proxy.getInvocationHandler(msLog); + Field value = invocationHandler.getClass().getDeclaredField("memberValues"); + value.setAccessible(true); + boolean isNext = false; for (Class clazz : msLog.msClass()) { + if (clazz.getName().equals("io.metersphere.commons.utils.SessionUtils")) { + Map memberValues = (Map) value.get(invocationHandler); + memberValues.put("operUser", SessionUtils.getUserId()); + continue; + } context.setVariable("msClass", applicationContext.getBean(clazz)); + isNext = true; + } + if (isNext) { + Expression expression = parser.parseExpression(msLog.beforeEvent()); + String beforeContent = expression.getValue(context, String.class); + Map memberValues = (Map) value.get(invocationHandler); + memberValues.put("beforeValue", beforeContent); } - Expression expression = parser.parseExpression(msLog.beforeEvent()); - String beforeContent = expression.getValue(context, String.class); - InvocationHandler invocationHandler = Proxy.getInvocationHandler(msLog); - Field value = invocationHandler.getClass().getDeclaredField("memberValues"); - value.setAccessible(true); - Map memberValues = (Map) value.get(invocationHandler); - memberValues.put("beforeValue", beforeContent); } - if (msLog != null && StringUtils.isEmpty(msLog.operUser())) { - InvocationHandler invocationHandler = Proxy.getInvocationHandler(msLog); - Field value = invocationHandler.getClass().getDeclaredField("memberValues"); - value.setAccessible(true); - Map memberValues = (Map) value.get(invocationHandler); - memberValues.put("operUser", SessionUtils.getUserId()); - } - } catch (Exception e) { LogUtil.error(e.getMessage()); } @@ -147,6 +148,9 @@ public class MsLogAspect { } for (Class clazz : msLog.msClass()) { + if (clazz.getName().equals("io.metersphere.commons.utils.SessionUtils")) { + continue; + } context.setVariable("msClass", applicationContext.getBean(clazz)); } // 项目ID 表达式