Browse Source

chore[litemall-core, litemall-admin-api]: Shiro的Exception采用专门的Handler处理

Junling Bu 7 years ago
parent
commit
4389c07313

+ 30 - 0
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/config/ShiroExceptionHandler.java

@@ -0,0 +1,30 @@
+package org.linlinjava.litemall.admin.config;
+
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authz.AuthorizationException;
+import org.linlinjava.litemall.core.util.ResponseUtil;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@ControllerAdvice
+@Order( value = Ordered.HIGHEST_PRECEDENCE )
+public class ShiroExceptionHandler {
+
+    @ExceptionHandler(AuthenticationException.class)
+    @ResponseBody
+    public Object unauthenticatedHandler(AuthenticationException e) {
+        e.printStackTrace();
+        return ResponseUtil.unlogin();
+    }
+
+    @ExceptionHandler(AuthorizationException.class)
+    @ResponseBody
+    public Object unauthorizedHandler(AuthorizationException e) {
+        e.printStackTrace();
+        return ResponseUtil.unauthz();
+    }
+
+}

+ 0 - 5
litemall-core/pom.xml

@@ -44,11 +44,6 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.shiro</groupId>
-            <artifactId>shiro-spring-boot-web-starter</artifactId>
-        </dependency>
-
-        <dependency>
             <groupId>com.aliyun.oss</groupId>
             <artifactId>aliyun-sdk-oss</artifactId>
             <exclusions>

+ 3 - 17
litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java

@@ -1,10 +1,9 @@
 package org.linlinjava.litemall.core.config;
 
-import org.apache.shiro.authc.AuthenticationException;
-import org.apache.shiro.authz.AuthorizationException;
-import org.apache.shiro.authz.UnauthorizedException;
 import org.hibernate.validator.internal.engine.path.PathImpl;
 import org.linlinjava.litemall.core.util.ResponseUtil;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
 import org.springframework.http.converter.HttpMessageNotReadableException;
 import org.springframework.web.bind.MissingServletRequestParameterException;
 import org.springframework.web.bind.annotation.ControllerAdvice;
@@ -18,6 +17,7 @@ import javax.validation.ValidationException;
 import java.util.Set;
 
 @ControllerAdvice
+@Order( value = Ordered.LOWEST_PRECEDENCE )
 public class GlobalExceptionHandler {
 
     @ExceptionHandler(IllegalArgumentException.class)
@@ -48,20 +48,6 @@ public class GlobalExceptionHandler {
         return ResponseUtil.badArgumentValue();
     }
 
-    @ExceptionHandler(AuthenticationException.class)
-    @ResponseBody
-    public Object unauthenticatedHandler(AuthenticationException e) {
-        e.printStackTrace();
-        return ResponseUtil.unlogin();
-    }
-
-    @ExceptionHandler(AuthorizationException.class)
-    @ResponseBody
-    public Object unauthorizedHandler(AuthorizationException e) {
-        e.printStackTrace();
-        return ResponseUtil.unauthz();
-    }
-
     @ExceptionHandler(ValidationException.class)
     @ResponseBody
     public Object badArgumentHandler(ValidationException e) {