2024-04-29 15:01:22 -06:00
|
|
|
package stirling.software.SPDF.config.security;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
import org.springframework.security.core.session.SessionRegistry;
|
|
|
|
import org.springframework.security.core.session.SessionRegistryImpl;
|
|
|
|
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-04-29 15:01:22 -06:00
|
|
|
@Bean
|
|
|
|
public SessionRegistry sessionRegistry() {
|
|
|
|
return new SessionRegistryImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-03 20:43:48 +01:00
|
|
|
sessionRegistry().removeSessionInformation(sessionId);
|
2024-04-29 15:01:22 -06:00
|
|
|
}
|
|
|
|
|
2024-05-03 20:43:48 +01:00
|
|
|
if (request.getParameter("oauth2AutoCreateDisabled") != null) {
|
|
|
|
response.sendRedirect(
|
|
|
|
request.getContextPath() + "/login?error=oauth2AutoCreateDisabled");
|
|
|
|
} else {
|
2024-04-29 15:01:22 -06:00
|
|
|
response.sendRedirect(request.getContextPath() + "/login?logout=true");
|
|
|
|
}
|
|
|
|
}
|
2024-05-03 20:43:48 +01:00
|
|
|
}
|