From cad3d298cc3b41f99c2a5c460660a2886e803d1b Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 3 Aug 2022 14:29:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E9=80=9A=E8=BF=87api?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3=E5=90=8E=EF=BC=8C=E6=9C=AC?= =?UTF-8?q?=E8=BA=AB=E6=9D=83=E9=99=90=E6=B2=A1=E6=9C=89=E5=8F=8A=E6=97=B6?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015603 --user=刘瑞斌 【系统设置】创建项目接口工作空间ID为空可成功创建 https://www.tapd.cn/55049933/s/1218355 --- .../controller/WorkspaceController.java | 2 + .../security/session/RefreshSession.java | 5 +++ .../session/RefreshSessionAspect.java | 37 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 backend/src/main/java/io/metersphere/security/session/RefreshSession.java create mode 100644 backend/src/main/java/io/metersphere/security/session/RefreshSessionAspect.java diff --git a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java index 530978f72a..c20aa030aa 100644 --- a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java +++ b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java @@ -14,6 +14,7 @@ import io.metersphere.dto.WorkspaceDTO; import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.dto.WorkspaceResource; import io.metersphere.log.annotation.MsAuditLog; +import io.metersphere.security.session.RefreshSession; import io.metersphere.service.UserService; import io.metersphere.service.WorkspaceService; import org.apache.shiro.authz.annotation.Logical; @@ -46,6 +47,7 @@ public class WorkspaceController { @PostMapping("special/add") @MsAuditLog(module = OperLogModule.SYSTEM_WORKSPACE, type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#workspace.id)", msClass = WorkspaceService.class) @RequiresPermissions(PermissionConstants.SYSTEM_WORKSPACE_READ_CREATE) + @RefreshSession public Workspace addWorkspaceByAdmin(@RequestBody Workspace workspace) { return workspaceService.addWorkspaceByAdmin(workspace); } diff --git a/backend/src/main/java/io/metersphere/security/session/RefreshSession.java b/backend/src/main/java/io/metersphere/security/session/RefreshSession.java new file mode 100644 index 0000000000..fed23e1ae6 --- /dev/null +++ b/backend/src/main/java/io/metersphere/security/session/RefreshSession.java @@ -0,0 +1,5 @@ +package io.metersphere.security.session; + +public @interface RefreshSession { + +} diff --git a/backend/src/main/java/io/metersphere/security/session/RefreshSessionAspect.java b/backend/src/main/java/io/metersphere/security/session/RefreshSessionAspect.java new file mode 100644 index 0000000000..65636c99dd --- /dev/null +++ b/backend/src/main/java/io/metersphere/security/session/RefreshSessionAspect.java @@ -0,0 +1,37 @@ +package io.metersphere.security.session; + +import io.metersphere.commons.user.SessionUser; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.dto.UserDTO; +import io.metersphere.service.UserService; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Aspect +@Component +public class RefreshSessionAspect { + + @Resource + private UserService userService; + + @Pointcut("@annotation(io.metersphere.security.session.RefreshSession)") + public void pointcut() { + } + + + @AfterReturning(value = "pointcut()", returning = "retValue") + public void sendNotice(JoinPoint joinPoint, Object retValue) { + try { + UserDTO userDTO = userService.getUserDTO(SessionUtils.getUserId()); + SessionUtils.putUser(SessionUser.fromUser(userDTO)); + } catch (Exception ignore) { + LogUtil.warn(ignore); + } + } +}