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 SummaryModifier and TypeMethodDescriptiongenerateToken(jakarta.servlet.http.HttpServletRequest request) Generates aCsrfTokendefault DeferredCsrfTokenloadDeferredToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Defers loading theCsrfTokenusing theHttpServletRequestandHttpServletResponseuntil it is needed by the application.loadToken(jakarta.servlet.http.HttpServletRequest request) Loads the expectedCsrfTokenfrom theHttpServletRequestvoidsaveToken(CsrfToken token, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) 
- 
Method Details- 
generateTokenGenerates aCsrfToken- Parameters:
- request- the- HttpServletRequestto use
- Returns:
- the CsrfTokenthat was generated. Cannot be null.
 
- 
saveTokenvoid 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- the- CsrfTokento save or null to delete
- request- the- HttpServletRequestto use
- response- the- HttpServletResponseto use
 
- 
loadTokenLoads the expectedCsrfTokenfrom theHttpServletRequest- Parameters:
- request- the- HttpServletRequestto use
- Returns:
- the CsrfTokenor null if none exists
 
- 
loadDeferredTokendefault DeferredCsrfToken loadDeferredToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Defers loading theCsrfTokenusing theHttpServletRequestandHttpServletResponseuntil it is needed by the application.The returned DeferredCsrfTokenis cached to allow subsequent calls toDeferredCsrfToken.get()to return the sameCsrfTokenwithout the cost of loading or generating the token again.- Parameters:
- request- the- HttpServletRequestto use
- response- the- HttpServletResponseto use
- Returns:
- a DeferredCsrfTokenthat will load theCsrfToken
- Since:
- 5.8
 
 
-