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 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
-
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
-
loadDeferredToken
default 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- theHttpServletRequestto useresponse- theHttpServletResponseto use- Returns:
- a
DeferredCsrfTokenthat will load theCsrfToken - Since:
- 5.8
-