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>