1 shiro @RequiresPermissions("user:test")认证失败后,无法在shiro配置文件中的<property name="unauthorizedUrl" value="/permError" />,实现跳转,而是在页面直接报异常。unauthorizedUrl不起作用,还没找到解决办法,只是把异常引导到了统一异常处理。解决办法一:
在spring mvc中,做异常映射处理:
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">/permError</prop>
</props>
</property>
</bean>
这里的permError,是一个controller中的@RequestMapping,这样一来,权限认证失败,就直接去permError,然后在函数内实现跳转
2 认证成功后,无法跳转到成功页面,
successUrl配置只是做为一种附加配置,只有session中没有用户请求地址时才会使用successUrl。系统默认的是认证成功后跳转到上一次请求的路径,如果是首次请求,那shiro就会跳转到默认虚拟路径“/”,也就是跳转到index.jsp。
a.如果是访问其他已存在的页面被拦截到登录页面,登录后就会跳转到之前的页面。
b.如果是直接访问登录页面或者是通过退出登录到登录页面,再次登录就会跳转到“/”。
c.不管怎么样,都没有跳转到successUrl指定的url。
方法有二
一、在index.jsp里面写跳转
<%
response.sendRedirect("first.action");
%>
二、在认证过滤器里面,FormAuthenticationFilter中,重写
@Override
protected void issueSuccessRedirect(ServletRequest request,
ServletResponse response) throws Exception {
WebUtils.issueRedirect(request, response, getSuccessUrl(), null, true);
}
在spring mvc中,做异常映射处理:
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">/permError</prop>
</props>
</property>
</bean>
这里的permError,是一个controller中的@RequestMapping,这样一来,权限认证失败,就直接去permError,然后在函数内实现跳转
2 认证成功后,无法跳转到成功页面,
successUrl配置只是做为一种附加配置,只有session中没有用户请求地址时才会使用successUrl。系统默认的是认证成功后跳转到上一次请求的路径,如果是首次请求,那shiro就会跳转到默认虚拟路径“/”,也就是跳转到index.jsp。
a.如果是访问其他已存在的页面被拦截到登录页面,登录后就会跳转到之前的页面。
b.如果是直接访问登录页面或者是通过退出登录到登录页面,再次登录就会跳转到“/”。
c.不管怎么样,都没有跳转到successUrl指定的url。
方法有二
一、在index.jsp里面写跳转
<%
response.sendRedirect("first.action");
%>
二、在认证过滤器里面,FormAuthenticationFilter中,重写
@Override
protected void issueSuccessRedirect(ServletRequest request,
ServletResponse response) throws Exception {
WebUtils.issueRedirect(request, response, getSuccessUrl(), null, true);
}