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); + } + } +}