fix(操作日志): 登出操作日志记录 #1005204

--bug=1005204 --user=赵勇 【系统设置-操作日志】... https://www.tapd.cn/55049933/s/1027443
This commit is contained in:
fit2-zhao 2021-07-21 17:49:47 +08:00 committed by fit2-zhao
parent 423a399779
commit 4114edd3d3
2 changed files with 20 additions and 16 deletions

View File

@ -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();

View File

@ -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<String, Object> memberValues = (Map<String, Object>) 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<String, Object> memberValues = (Map<String, Object>) 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<String, Object> memberValues = (Map<String, Object>) 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<String, Object> memberValues = (Map<String, Object>) 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 表达式