-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eagerly fetch csrf token for single page application
- Loading branch information
1 parent
f85fba3
commit 9134561
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
.../de/webalf/slotbot/configuration/authentication/website/AuthenticationSuccessHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.webalf.slotbot.configuration.authentication.website; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
import org.springframework.security.web.csrf.CsrfToken; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author Alf | ||
* @since 21.02.2023 | ||
*/ | ||
@Component | ||
public class AuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { | ||
@Override | ||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { | ||
// https://github.com/spring-projects/spring-security/issues/12094#issuecomment-1294150717 | ||
CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); | ||
csrfToken.getToken(); | ||
|
||
super.onAuthenticationSuccess(request, response, authentication); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters