Sfoglia il codice sorgente

【编辑】 权限切面提示问题处理

linfutong 3 anni fa
parent
commit
cc3ad67589

+ 10 - 8
zd-common/common-core/src/main/java/com/zd/common/core/aspect/PreAuthorizeAspect.java

@@ -1,6 +1,7 @@
 package com.zd.common.core.aspect;
 
 import com.zd.common.core.annotation.PreAuthorize;
+import com.zd.common.core.exception.PreAuthorizeException;
 import com.zd.common.core.security.TokenService;
 import com.zd.common.core.utils.StringUtils;
 import com.zd.model.entity.LoginUser;
@@ -14,8 +15,10 @@ import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.PatternMatchUtils;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.Method;
 import java.util.Collection;
+import java.util.Set;
 
 /**
  * 自定义权限实现
@@ -52,38 +55,37 @@ public class PreAuthorizeAspect {
         if (annotation == null) {
             return point.proceed();
         }
-
-
+        //权限验证
         if (StringUtils.isNotEmpty(annotation.hasPermi())) {
             if (hasPermi(annotation.hasPermi())) {
                 return point.proceed();
             }
-            throw new RuntimeException();
+            throw new PreAuthorizeException();
         } else if (StringUtils.isNotEmpty(annotation.lacksPermi())) {
             if (lacksPermi(annotation.lacksPermi())) {
                 return point.proceed();
             }
-            throw new RuntimeException();
+            throw new PreAuthorizeException();
         } else if (ARRAY_EMPTY < annotation.hasAnyPermi().length) {
             if (hasAnyPermi(annotation.hasAnyPermi())) {
                 return point.proceed();
             }
-            throw new RuntimeException();
+            throw new PreAuthorizeException();
         } else if (StringUtils.isNotEmpty(annotation.hasRole())) {
             if (hasRole(annotation.hasRole())) {
                 return point.proceed();
             }
-            throw new RuntimeException();
+            throw new PreAuthorizeException();
         } else if (StringUtils.isNotEmpty(annotation.lacksRole())) {
             if (lacksRole(annotation.lacksRole())) {
                 return point.proceed();
             }
-            throw new RuntimeException();
+            throw new PreAuthorizeException();
         } else if (ARRAY_EMPTY < annotation.hasAnyRoles().length) {
             if (hasAnyRoles(annotation.hasAnyRoles())) {
                 return point.proceed();
             }
-            throw new RuntimeException();
+            throw new PreAuthorizeException();
         }
 
         return point.proceed();

+ 1 - 1
zd-common/common-core/src/main/java/com/zd/common/core/exception/GlobalExceptionHandler.java

@@ -32,7 +32,7 @@ public class GlobalExceptionHandler {
     public AjaxResult handlePreAuthorizeException(PreAuthorizeException e, HttpServletRequest request) {
         String requestURI = request.getRequestURI();
         log.error("请求地址'{}',权限校验失败'{}'", requestURI, e.getMessage());
-        return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员授权");
+        return AjaxResult.error(HttpStatus.FORBIDDEN, "没有权限,请联系管理员");
     }
 
     /**