setUnauthorizedUrl("/403")不起作用
SpringBoot中集成Shiro的时候, 配置setUnauthorizedUrl("/403")了,但是不起作用,只会在控制台打印UnauthorizedException异常信息:
原因:
Shiro源码中是这样做的:
private void applyUnauthorizedUrlIfNecessary(Filter filter) {
String unauthorizedUrl = this.getUnauthorizedUrl();
if(StringUtils.hasText(unauthorizedUrl) && filter instanceof AuthorizationFilter) {
AuthorizationFilter authzFilter = (AuthorizationFilter)filter;
String existingUnauthorizedUrl = authzFilter.getUnauthorizedUrl();
if(existingUnauthorizedUrl == null) {
authzFilter.setUnauthorizedUrl(unauthorizedUrl);
}
}
}
在SpringBoot集成Shiro时,设置setUnauthorizedUrl('/403')无法正常工作,因为Shiro源码中只有特定的过滤器才会响应unauthorizedUrl。要处理UnauthorizedException,可以自定义异常处理,如创建一个继承自HandlerExceptionResolver的类来捕获并处理UnauthorizedException。
订阅专栏 解锁全文
1677

被折叠的 条评论
为什么被折叠?



