From 8fdcd576c91b567c3e3424549f170aac024f9464 Mon Sep 17 00:00:00 2001
From: JuJu <857815116@qq.com>
Date: Fri, 23 Oct 2020 16:00:39 +0800
Subject: [PATCH] 修正hasRole匹配为equals

---
 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java
index 777b5b1..3a44d82 100644
--- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java
+++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java
@@ -35,6 +35,9 @@
     /** 管理员角色权限标识 */
     private static final String SUPER_ADMIN = "admin";
 
+    /** 数组为0时 */
+    private static final Integer ARRAY_EMPTY = 0;
+
     @Around("@annotation(com.ruoyi.common.security.annotation.PreAuthorize)")
     public Object around(ProceedingJoinPoint point) throws Throwable
     {
@@ -63,7 +66,7 @@
             }
             throw new PreAuthorizeException();
         }
-        else if (!StringUtils.isEmpty(annotation.hasAnyPermi()))
+        else if (ARRAY_EMPTY < annotation.hasAnyPermi().length)
         {
             if (hasAnyPermi(annotation.hasAnyPermi()))
             {
@@ -79,7 +82,7 @@
             }
             throw new PreAuthorizeException();
         }
-        else if (StringUtils.isEmpty(annotation.lacksRole()))
+        else if (!StringUtils.isEmpty(annotation.lacksRole()))
         {
             if (lacksRole(annotation.lacksRole()))
             {
@@ -87,7 +90,7 @@
             }
             throw new PreAuthorizeException();
         }
-        else if (StringUtils.isEmpty(annotation.hasAnyRoles()))
+        else if (ARRAY_EMPTY < annotation.hasAnyRoles().length)
         {
             if (hasAnyRoles(annotation.hasAnyRoles()))
             {
@@ -165,7 +168,7 @@
         }
         for (String roleKey : userInfo.getRoles())
         {
-            if (SUPER_ADMIN.contains(roleKey) || roleKey.contains(role))
+            if (SUPER_ADMIN.equals(roleKey) || roleKey.equals(role))
             {
                 return true;
             }

--
Gitblit v1.9.3