使用shiro进行系统身份验证-权限控制,登录界面乱跳

来源:互联网 发布:手机淘宝网怎么发链接 编辑:程序博客网 时间:2024/05/18 02:13

问题描述;shiro验证成功后,跳转页面不是shiro.xml文件中配置的跳转地址

1.自定义MyFormAuthenticationFilter继承FormAuthenticationFilter并重写onLoginSuccess方法

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;


import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;


public class MyFormAuthenticationFilter extends FormAuthenticationFilter {


@Override
protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request,
ServletResponse response) throws Exception {
    WebUtils.getAndClearSavedRequest(request);
    WebUtils.redirectToSavedRequest(request, response, getSuccessUrl());
return false;
}


}

2.在spring-shiro.xml文件中加入自定义类

<property name="filters">
      <util:map>     
    <entry key="authc">
     <bean class="cn.realms.MyFormAuthenticationFilter" />
    </entry>
   
  </util:map>
  
  </property>

以上可以解决登录乱跳情况(一般是返回上一次登录的页面)

原创粉丝点击