Spring Security: Redirect to invalid-session-url instead of logout-success-url on successful logout

logoutsession-managementspringspring-security

I have implemented a login-logout system with Spring Security 3.0.2, everything is fine but for this one thing: after I added a session-management tag with invalid-session-url attribute, on logout Spring would always redirect me on the invalid-session-url instead of the logout-success-url (which it correctly did before).

Is there a way to avoid this behaviour?

This is my configuration:

<http use-expressions="true" auto-config="true">
        [...some intercept-url's...]

    <form-login login-page="/login" authentication-failure-url="/login?error=true"
            login-processing-url="/login-submit" default-target-url="/home"
            always-use-default-target="true" />

    <logout logout-success-url="/home?logout=true" logout-url="/login-logout" />

    <session-management invalid-session-url="/home?invalid=true" />
</http>

Thanks a lot.

Best Answer

By default, the logout process will first invalidate the session, hence triggering the session management to redirect to the invalid session page. By specifying invalidate-session="false" will fix this behavior.

<sec:logout logout-success-url="/logout" invalidate-session="false" 
delete-cookies="JSESSIONID" />