使用shrio,集成到springmvc后,访问带有@RequirePermission注解的方法,This subject is anonymous - it does not have any identifying principals and authorization operations require an identity to check against. A Subject instance will acquire these identifying principals automatically after a successful login is performed ..
未登录的情况下,访问需要登陆后才能使用的链接/接口回抛出如上异常。解决方法是,在springmvc.xml中添加全局异常捕获,捕获异常类:org.apache.shiro.authz.UnauthenticatedException。并返回错误页面
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">error/403</prop><!-- 未授权使用的异常 -->
<prop key="org.apache.shiro.authz.UnauthenticatedException">error/403</prop><!-- 其他 -->
<prop key="java.lang.Throwable">error/500</prop>
</props>
</property>
</bean>