2024-04-29 15:01:22 -06:00
|
|
|
package stirling.software.SPDF.config.security;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2024-05-12 19:58:34 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-04-29 15:01:22 -06:00
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
import org.springframework.security.core.session.SessionRegistry;
|
|
|
|
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
|
|
|
|
|
2024-05-03 20:43:48 +01:00
|
|
|
import jakarta.servlet.ServletException;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
import jakarta.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {
|
2024-05-12 19:58:34 +02:00
|
|
|
|
|
|
|
@Autowired SessionRegistry sessionRegistry;
|
2024-04-29 15:01:22 -06:00
|
|
|
|
|
|
|
@Override
|
2024-05-03 20:43:48 +01:00
|
|
|
public void onLogoutSuccess(
|
|
|
|
HttpServletRequest request, HttpServletResponse response, Authentication authentication)
|
|
|
|
throws IOException, ServletException {
|
2024-04-29 15:01:22 -06:00
|
|
|
HttpSession session = request.getSession(false);
|
|
|
|
if (session != null) {
|
|
|
|
String sessionId = session.getId();
|
2024-05-12 19:58:34 +02:00
|
|
|
sessionRegistry.removeSessionInformation(sessionId);
|
2024-04-29 15:01:22 -06:00
|
|
|
}
|
|
|
|
|
2024-05-12 19:58:34 +02:00
|
|
|
response.sendRedirect(request.getContextPath() + "/login?logout=true");
|
2024-04-29 15:01:22 -06:00
|
|
|
}
|
2024-05-03 20:43:48 +01:00
|
|
|
}
|