I cant use Spring Security LogoutSuccessHandler but only in my current project. Previously, everything worker properly but now its not used.
Here is the class:
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component("customLogoutSuccessHandler") //or implements LogoutSuccessHandler
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
@Override
public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
System.err.println("LOGOUT HANDLER HERE");
}
}
And here is my xml config
<security:http auto-config="false" >
<security:logout logout-url="/logout" success-handler-ref="customLogoutSuccessHandler"/>
<security:form-login login-page="/login" default-target-url="/"/>
<security:csrf/>
</security:http>
Whats wrong with the code? onLogoutSuccess method is never run even if I am logged out:
@RequestMapping(value = "/logout")
public String logout(){
SecurityContextHolder.clearContext();
return "redirect:/";
}
Why?