Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
4389c073
Commit
4389c073
authored
Jan 16, 2019
by
Junling Bu
Browse files
chore[litemall-core, litemall-admin-api]: Shiro的Exception采用专门的Handler处理
parent
f68e674c
Changes
3
Hide whitespace changes
Inline
Side-by-side
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/config/ShiroExceptionHandler.java
0 → 100644
View file @
4389c073
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
();
}
}
litemall-core/pom.xml
View file @
4389c073
...
@@ -43,11 +43,6 @@
...
@@ -43,11 +43,6 @@
</exclusions>
</exclusions>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.shiro
</groupId>
<artifactId>
shiro-spring-boot-web-starter
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
com.aliyun.oss
</groupId>
<groupId>
com.aliyun.oss
</groupId>
<artifactId>
aliyun-sdk-oss
</artifactId>
<artifactId>
aliyun-sdk-oss
</artifactId>
...
...
litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java
View file @
4389c073
package
org.linlinjava.litemall.core.config
;
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.hibernate.validator.internal.engine.path.PathImpl
;
import
org.linlinjava.litemall.core.util.ResponseUtil
;
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.http.converter.HttpMessageNotReadableException
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
...
@@ -18,6 +17,7 @@ import javax.validation.ValidationException;
...
@@ -18,6 +17,7 @@ import javax.validation.ValidationException;
import
java.util.Set
;
import
java.util.Set
;
@ControllerAdvice
@ControllerAdvice
@Order
(
value
=
Ordered
.
LOWEST_PRECEDENCE
)
public
class
GlobalExceptionHandler
{
public
class
GlobalExceptionHandler
{
@ExceptionHandler
(
IllegalArgumentException
.
class
)
@ExceptionHandler
(
IllegalArgumentException
.
class
)
...
@@ -48,20 +48,6 @@ public class GlobalExceptionHandler {
...
@@ -48,20 +48,6 @@ public class GlobalExceptionHandler {
return
ResponseUtil
.
badArgumentValue
();
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
)
@ExceptionHandler
(
ValidationException
.
class
)
@ResponseBody
@ResponseBody
public
Object
badArgumentHandler
(
ValidationException
e
)
{
public
Object
badArgumentHandler
(
ValidationException
e
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment