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);
}
}
}
只有perms,roles,ssl,rest,port才是属于AuthorizationFilter,而anon