Shrio : This subject is anonymous - it does not have any identifying principals and

来源:互联网 发布:淘宝商品资质怎么弄 编辑:程序博客网 时间:2024/05/16 07:46

                  使用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>



0 0