From 4114edd3d3a96094bdf43a876d3782d1369e4678 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 21 Jul 2021 17:49:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97):=20?= =?UTF-8?q?=E7=99=BB=E5=87=BA=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=20#1005204=20--bug=3D1005204=20--user=3D=E8=B5=B5?= =?UTF-8?q?=E5=8B=87=20=E3=80=90=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE-?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E3=80=91...=20https://www.?= =?UTF-8?q?tapd.cn/55049933/s/1027443?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginController.java | 2 +- .../metersphere/log/aspect/MsLogAspect.java | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) 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 表达式