您的位置:首页 > 其它

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

2016-11-24 11:23 966 查看
                  使用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>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐