From aadb7a41cb4c69177a0251c251813070f7f97cd5 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 22 Aug 2022 10:24:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Context=E4=BF=A1=E6=81=AF,?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/system/SysRoleController.java | 3 +-- .../com/ruoyi/common/constant/UserConstants.java | 5 ----- .../security/context/PermissionContextHolder.java | 12 +++++++++--- .../ruoyi/framework/web/service/SysLoginService.java | 4 ++++ .../main/resources/mapper/system/SysMenuMapper.xml | 1 - 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java index 76731f07..a2c8d4de 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -251,7 +251,7 @@ public class SysRoleController extends BaseController /** * 获取对应角色部门树列表 */ - @PreAuthorize("@ss.hasPermi('system:role:list')") + @PreAuthorize("@ss.hasPermi('system:role:query')") @GetMapping(value = "/deptTree/{roleId}") public AjaxResult deptTree(@PathVariable("roleId") Long roleId) { @@ -260,5 +260,4 @@ public class SysRoleController extends BaseController ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); return ajax; } - } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java index 737c9d50..c6c7797b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java @@ -12,11 +12,6 @@ public class UserConstants */ public static final String SYS_USER = "SYS_USER"; - /** - * ss标记的权限字符 - */ - public static final String SS_PERMISSION = "SS_PERMISSION"; - /** 正常状态 */ public static final String NORMAL = "0"; diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/context/PermissionContextHolder.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/context/PermissionContextHolder.java index fcd93b68..2fcd65b4 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/context/PermissionContextHolder.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/context/PermissionContextHolder.java @@ -1,5 +1,9 @@ package com.ruoyi.framework.security.context; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import com.ruoyi.common.core.text.Convert; + /** * 权限信息 * @@ -7,15 +11,17 @@ package com.ruoyi.framework.security.context; */ public class PermissionContextHolder { - private static final ThreadLocal contextHolder = new ThreadLocal<>(); + private static final String PERMISSION_CONTEXT_ATTRIBUTES = "PERMISSION_CONTEXT"; public static void setContext(String permission) { - contextHolder.set(permission); + RequestContextHolder.currentRequestAttributes().setAttribute(PERMISSION_CONTEXT_ATTRIBUTES, permission, + RequestAttributes.SCOPE_REQUEST); } public static String getContext() { - return contextHolder.get(); + return Convert.toStr(RequestContextHolder.currentRequestAttributes().getAttribute(PERMISSION_CONTEXT_ATTRIBUTES, + RequestAttributes.SCOPE_REQUEST)); } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 08157b6d..56669a7a 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -89,6 +89,10 @@ public class SysLoginService throw new ServiceException(e.getMessage()); } } + finally + { + AuthenticationContextHolder.clearContext(); + } AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); recordLoginInfo(loginUser.getUserId()); diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index a8dc0b92..e90f6baf 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -118,7 +118,6 @@ where m.status = '0' and rm.role_id = #{roleId} -