本文介绍了spring security自定义注销处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在spring-security中将自己的注销处理程序添加到LogoutFilter?
谢谢!
How can I add my own logout handler to LogoutFilter in spring-security ?Thanks!
推荐答案
以下解决方案适合我,可能会有所帮助:
The following solution works for me and may be helpful:
-
扩展或实现:
public class LogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
// Just for setting the default target URL
public LogoutSuccessHandler(String defaultTargetURL) {
this.setDefaultTargetUrl(defaultTargetURL);
}
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
// do whatever you want
super.onLogoutSuccess(request, response, authentication);
}
}
添加到Spring安全配置:
Add to your Spring Security Configuration:
<security:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" />
<bean id="logoutSuccessHandler" class="your.package.name.LogoutSuccessHandler" >
<constructor-arg value="/putInYourDefaultTargetURLhere" />
</bean>
这篇关于spring security自定义注销处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!