Interface CsrfTokenRepository
- All Known Implementing Classes:
CookieCsrfTokenRepository, HttpSessionCsrfTokenRepository
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.@Nullable CsrfTokenloadToken(jakarta.servlet.http.HttpServletRequest request) Loads the expectedCsrfTokenfrom theHttpServletRequestvoidsaveToken(@Nullable CsrfToken token, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
-
Method Details
-
generateToken
-
saveToken
void saveToken(@Nullable 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
-
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
-