向Spring Security Logout添加参数

时间:2014-06-20 11:13:23

标签: spring spring-security spring-security-ldap

Hai我可以向Spring Security Logout添加参数。我在security.xml中配置了logout请求,如下所示。

<sec:logout invalidate-session="true" logout-success-url="/logoutsuccess.do" logout-url="/logout.do" />

登录成功登录后,我正在验证自定义成功处理程序上用户帐户的各个方面,以验证帐户订阅状态,批准/拒绝等,如果有任何条件失败,将根据它发送注销请求。我想在注销页面上显示自定义错误消息,因此希望将该参数与注销请求一起发送。

1 个答案:

答案 0 :(得分:2)

编写自定义注销处理程序。将属性success-handler-ref放在xml配置文件中。

e.g

<sec:logout invalidate-session="true" logout-success-url="/logoutsuccess.do" 
  logout-url="/logout.do" 
  success-handler-ref="YourCustomLogoutSuccessHandler"/>

然后扩展SimpleUrlLogoutSuccessHandler或实施LogoutHandler

e.g

public class YourCustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {  

    @Override  
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,  
            Authentication authentication) throws IOException, ServletException {  

        //Do what you want to do here
        //....... 

        //below does the 'standard' spring logout handling  
        super.onLogoutSuccess(request, response, authentication);         
    }  
} 

另一种方法是here。这还显示了如何重定向到特定URL并手动处理会话管理。