UnauthorizedException授权异常
设置了权限不足跳转的页面:(shiroFilterFactoryBean.setUnauthorizedUrl("/url"))
原因:这个url必须满足两个条件,即不为空,并且filter是AuthorizationFilter,然后,只有perms,roles,ssl,rest,port才是属于AuthorizationFilter,而anon,authcBasic,auchc,user是AuthenticationFilter,所以unauthorizedUrl设置后页面不跳转。
方案
- 使用perms,roles,ssl,rest,port
- 配置error页面,这针对所有的error页面
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
- 配置所有的抛出无权限异常的页面(不合理程度同上)
<error-page>
<exceptiontype>org.apache.shiro.authz.UnauthorizedException</exception-type>
<location>/unauthorized.jsp</location>
</error-page>
- 对抛出的异常进行统一处理跳转。
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">/errorpage/refuse</prop>
</props>
</property>
</bean>
本文探讨了在使用Shiro框架时遇到的UnauthorizedException异常,详细分析了设置unauthorizedUrl无效的原因,提供了通过配置error页面、异常类型映射及统一异常处理来解决无权限访问问题的有效策略。
5213

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



