diff --git a/backend/src/main/java/io/metersphere/controller/LoginController.java b/backend/src/main/java/io/metersphere/controller/LoginController.java index 25d28015b5bc..6481280ff2b8 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 ResultHolder currentUser() { } @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 976395b50efa..f454dc3a0acd 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 void before(JoinPoint joinPoint) { for (int len = 0; len < params.length; len++) { context.setVariable(params[len], args[len]); } - for (Class clazz : msLog.msClass()) { - context.setVariable("msClass", applicationContext.getBean(clazz)); - } - 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()); + 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); + } } - } catch (Exception e) { LogUtil.error(e.getMessage()); } @@ -147,6 +148,9 @@ public void saveLog(JoinPoint joinPoint) { } for (Class clazz : msLog.msClass()) { + if (clazz.getName().equals("io.metersphere.commons.utils.SessionUtils")) { + continue; + } context.setVariable("msClass", applicationContext.getBean(clazz)); } // 项目ID 表达式