1.修改配置文件
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> ... <property name="filters"> <util:map> <entry key="authc" value-ref="formAuthenticationFilter"/> </util:map> </property> ... </bean> <!-- 自定义验证拦截器 --> <bean id="formAuthenticationFilter" class="****.LZFormAuthenticationFilter"/>
2.扩展FormAuthenticationFilter
public class LZFormAuthenticationFilter extends FormAuthenticationFilter { /** * 重写登录地址 */ protected void redirectToLogin(ServletRequest request,ServletResponse response) throws IOException { //request.getLocalAddr() HttpServletRequest req=(HttpServletRequest) request; String loginUrl = getLoginUrl(); String url=req.getRequestURI(); if(url.contains("/mine/")){ loginUrl="/web/teacher/list.htm"; } WebUtils.issueRedirect(request, response, loginUrl); } }3. 动态增加shiro的filter地址,可以继承 DefaultFilterChainManager
<property name="filterChainDefinitions"> <value> /favicon.ico = anon /resources/**=anon /**/*.jpg = anon </value> </property>