1. 程式人生 > >shiro登入成功後指定跳轉頁面

shiro登入成功後指定跳轉頁面

1.自定義一個 MyFormAuthenticationFilter 繼承 FormAuthenticationFilter 

public class MyFormAuthenticationFilter extends FormAuthenticationFilter{



@Override
protected boolean onLoginSuccess(AuthenticationToken token,
Subject subject, ServletRequest request, ServletResponse response)
throws Exception {
HttpServletResponse httpResponse=(HttpServletResponse) response;
httpResponse.sendRedirect("index.action");
return true;
}


}

2.在 httpResponse.sendRedirect(url);指定你要跳轉的url。

3.spring 中配置自定義FormAuthenticationFilter 

<bean id="formAuthenticationFilter" class="com.shiro.MyFormAuthenticationFilter ">
<!-- 表單中賬號的input名稱 -->
<property name="usernameParam" value="username" />
<!-- 表單中密碼的input名稱 -->
<property name="passwordParam" value="password" />
 </bean>

4.ShiroFilterFactoryBean 配置中配置自定義FormAuthenticationFilter 

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">

<property name="filters">
<map>
<!-- 將自定義 的FormAuthenticationFilter注入shiroFilter中-->
<entry key="authc" value-ref="formAuthenticationFilter" />
</map>
</property>

</bean>