This commit is contained in:
Anthony Stirling 2024-09-06 19:06:00 +02:00
parent 7ccb4d59b0
commit 8ea179e3e6
2 changed files with 17 additions and 1 deletions

View File

@ -45,7 +45,15 @@ public class CustomAuthenticationSuccessHandler
? (SavedRequest) session.getAttribute("SPRING_SECURITY_SAVED_REQUEST")
: null;
if (savedRequest != null
// Check for the stored previous page URL
String previousPageUrl = (session != null) ? (String) session.getAttribute("PREVIOUS_PAGE_URL") : null;
if (previousPageUrl != null) {
// Redirect to the stored previous page URL
getRedirectStrategy().sendRedirect(request, response, previousPageUrl);
// Remove the stored previous page URL from the session
session.removeAttribute("PREVIOUS_PAGE_URL");
} else if (savedRequest != null
&& !RequestUriUtils.isStaticResource(
request.getContextPath(), savedRequest.getRedirectUrl())) {
// Redirect to the original destination

View File

@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.config.security.session.SessionPersistentRegistry;
import stirling.software.SPDF.model.*;
@ -49,6 +50,13 @@ public class AccountWebController {
return "redirect:/";
}
// Store the previous page URL in the session before redirecting to the login page
HttpSession session = request.getSession();
String referer = request.getHeader("Referer");
if (referer != null && !referer.contains("/login")) {
session.setAttribute("PREVIOUS_PAGE_URL", referer);
}
Map<String, String> providerList = new HashMap<>();
OAUTH2 oauth = applicationProperties.getSecurity().getOAUTH2();