From fb8eac70649ca8deb4aee000b7151da0db8d37b3 Mon Sep 17 00:00:00 2001
From: Mask <mask616@163.com>
Date: Wed, 21 Apr 2021 16:31:21 +0800
Subject: [PATCH] 优化注释

---
 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java |   82 ++++++++++++++++++++++++++++-------------
 1 files changed, 56 insertions(+), 26 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 f38039c..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
@@ -17,6 +17,11 @@
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.system.api.model.LoginUser;
 
+/**
+ * 自定义权限实现
+ * 
+ * @author ruoyi
+ */
 @Aspect
 @Component
 public class PreAuthorizeAspect
@@ -30,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
     {
@@ -42,34 +50,56 @@
             return point.proceed();
         }
 
-        if (StringUtils.isEmpty(annotation.hasPermi()) && hasPermi(annotation.hasPermi()))
+        if (!StringUtils.isEmpty(annotation.hasPermi()))
         {
-            return point.proceed();
-        }
-        else if (StringUtils.isEmpty(annotation.lacksPermi()) && hasPermi(annotation.lacksPermi()))
-        {
-            return point.proceed();
-        }
-        else if (StringUtils.isEmpty(annotation.hasAnyPermi()) && hasAnyPermi(annotation.hasAnyPermi()))
-        {
-            return point.proceed();
-        }
-        else if (StringUtils.isEmpty(annotation.hasRole()) && hasRole(annotation.hasRole()))
-        {
-            return point.proceed();
-        }
-        else if (StringUtils.isEmpty(annotation.lacksRole()) && lacksRole(annotation.lacksRole()))
-        {
-            return point.proceed();
-        }
-        else if (StringUtils.isEmpty(annotation.hasAnyRoles()) && hasAnyRoles(annotation.hasAnyRoles()))
-        {
-            return point.proceed();
-        }
-        else
-        {
+            if (hasPermi(annotation.hasPermi()))
+            {
+                return point.proceed();
+            }
             throw new PreAuthorizeException();
         }
+        else if (!StringUtils.isEmpty(annotation.lacksPermi()))
+        {
+            if (lacksPermi(annotation.lacksPermi()))
+            {
+                return point.proceed();
+            }
+            throw new PreAuthorizeException();
+        }
+        else if (ARRAY_EMPTY < annotation.hasAnyPermi().length)
+        {
+            if (hasAnyPermi(annotation.hasAnyPermi()))
+            {
+                return point.proceed();
+            }
+            throw new PreAuthorizeException();
+        }
+        else if (!StringUtils.isEmpty(annotation.hasRole()))
+        {
+            if (hasRole(annotation.hasRole()))
+            {
+                return point.proceed();
+            }
+            throw new PreAuthorizeException();
+        }
+        else if (!StringUtils.isEmpty(annotation.lacksRole()))
+        {
+            if (lacksRole(annotation.lacksRole()))
+            {
+                return point.proceed();
+            }
+            throw new PreAuthorizeException();
+        }
+        else if (ARRAY_EMPTY < annotation.hasAnyRoles().length)
+        {
+            if (hasAnyRoles(annotation.hasAnyRoles()))
+            {
+                return point.proceed();
+            }
+            throw new PreAuthorizeException();
+        }
+
+        return point.proceed();
     }
 
     /**
@@ -138,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