shiro unauthorizedurl 怎么不是当前页面而是父页面的

2024-12-20 12:47:33
推荐回答(1个)
回答1:

解决方法:

1、mvc




none_authority



2、web.xml


500
/error.jsp


原因:

shiro的源代码ShiroFilterFactoryBean.java

[java] view
plaincopy

private void applyUnauthorizedUrlIfNecessary(Filter filter) {
String unauthorizedUrl = getUnauthorizedUrl();
if (StringUtils.hasText(unauthorizedUrl) && (filter instanceof AuthorizationFilter)) {
AuthorizationFilter authzFilter = (AuthorizationFilter) filter;
//only apply the unauthorizedUrl if they haven't explicitly configured one already:
String existingUnauthorizedUrl = authzFilter.getUnauthorizedUrl();
if (existingUnauthorizedUrl == null) {
authzFilter.setUnauthorizedUrl(unauthorizedUrl);
}
}
}

定义的filter必须满足filter
instanceof
AuthorizationFilter,只有perms,roles,ssl,rest,port才是属于AuthorizationFilter,而anon,authcBasic,auchc,user是AuthenticationFilter,所以unauthorizedUrl设置后页面不跳转