shiro 自定义logout路径

来源:互联网 发布:济南网站怎么优化 编辑:程序博客网 时间:2024/05/20 02:30

分享一个shiro 自定义 logout 路径的方法。(亲测可用)

shiro默认logout路径是主页,可是实际开发中并不想这样。尝试了网上的两种方法都失败了。在无数的疼苦挣扎中找到了一种适合自己的方法。我用的框架是Spring + SpringMVC + Spring data jpa 。需要的朋友可以参考一下。

在shiro的配置文件中设置。

<!-- 自定义退出路径 --><bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">         <property name="redirectUrl" value="/login"/>     </bean> <!-- Shiro Filter --><bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"><property name="securityManager" ref="securityManager" /><property name="loginUrl" value="/login" /><property name="successUrl" value="/" /><property name="filterChainDefinitions"><value>/login = authc/logout = logout</value></property><property name="filters">    <map>        <entry key="logout" value-ref="logout" />    </map></property></bean>

logout需要配置三个地方。一个是bean , 一个是 filterChainDefinitions , 一个是 filters。

redirectUrl 的 value 便是自定义 logout 的路径。为了避免不必要的错误,建议把bean的id设置为logout。

希望能帮到大家!

个人主页:http://www.itit123.cn/ 更多干货等你来拿

2 0
原创粉丝点击