1、自定义过滤器
/**
* 自定义的过滤器
* 实现shiro登录成功后跳到指定的URL
* @author ASUS
*
*/
public class LoginFormAuthenticationFilter extends FormAuthenticationFilter {
//重写该方法清掉之前的URL,防止登录成功后跳到那个URL
@Override
protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request,
ServletResponse response) throws Exception {
//清理原先的URL
WebUtils.getAndClearSavedRequest(request);
//登录成功后跳转到/home
WebUtils.redirectToSavedRequest(request, response, "/home");
return false;
}
}
2、配置shiro配置文件
<!-- 自定义过滤器 -->
<bean id="loginFormAuthenticationFilter" class="com.wwz.bookSystem.shiro.LoginFormAuthenticationFilter"/>
<!-- 定义ShiroFilter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login"/>
<property name="successUrl" value="/home"/>
<property name="unauthorizedUrl" value="/nopermission"/>
<!-- 配置自定义的过滤器 -->
<property name="filters">
<map>
<entry key="authc" value-ref="loginFormAuthenticationFilter" />
</map>
</property>
<property name="filterChainDefinitions">
<value>
/resources/**=anon
/register/**=anon
/login/**=anon
/logout=logout
/**=authc
</value>
</property>
</bean>