Interface CsrfTokenRepository
- All Known Implementing Classes:
CookieCsrfTokenRepository,HttpSessionCsrfTokenRepository,LazyCsrfTokenRepository
public interface CsrfTokenRepository
An API to allow changing the method in which the expected
CsrfToken is
associated to the HttpServletRequest. For example, it may be stored in
HttpSession.- Since:
- 3.2
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongenerateToken(jakarta.servlet.http.HttpServletRequest request) Generates aCsrfTokenloadToken(jakarta.servlet.http.HttpServletRequest request) Loads the expectedCsrfTokenfrom theHttpServletRequestvoidsaveToken(CsrfToken token, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
-
Method Details
-
generateToken
Generates aCsrfToken- Parameters:
request- theHttpServletRequestto use- Returns:
- the
CsrfTokenthat was generated. Cannot be null.
-
saveToken
void saveToken(CsrfToken token, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Saves theCsrfTokenusing theHttpServletRequestandHttpServletResponse. If theCsrfTokenis null, it is the same as deleting it.- Parameters:
token- theCsrfTokento save or null to deleterequest- theHttpServletRequestto useresponse- theHttpServletResponseto use
-
loadToken
Loads the expectedCsrfTokenfrom theHttpServletRequest- Parameters:
request- theHttpServletRequestto use- Returns:
- the
CsrfTokenor null if none exists
-