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 aCsrfToken
default DeferredCsrfToken
loadDeferredToken
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Defers loading theCsrfToken
using theHttpServletRequest
andHttpServletResponse
until it is needed by the application.loadToken
(jakarta.servlet.http.HttpServletRequest request) Loads the expectedCsrfToken
from theHttpServletRequest
void
saveToken
(CsrfToken token, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
-
Method Details
-
generateToken
Generates aCsrfToken
- Parameters:
request
- theHttpServletRequest
to use- Returns:
- the
CsrfToken
that was generated. Cannot be null.
-
saveToken
void saveToken(CsrfToken token, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Saves theCsrfToken
using theHttpServletRequest
andHttpServletResponse
. If theCsrfToken
is null, it is the same as deleting it.- Parameters:
token
- theCsrfToken
to save or null to deleterequest
- theHttpServletRequest
to useresponse
- theHttpServletResponse
to use
-
loadToken
Loads the expectedCsrfToken
from theHttpServletRequest
- Parameters:
request
- theHttpServletRequest
to use- Returns:
- the
CsrfToken
or null if none exists
-
loadDeferredToken
default DeferredCsrfToken loadDeferredToken(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Defers loading theCsrfToken
using theHttpServletRequest
andHttpServletResponse
until it is needed by the application.The returned
DeferredCsrfToken
is cached to allow subsequent calls toDeferredCsrfToken.get()
to return the sameCsrfToken
without the cost of loading or generating the token again.- Parameters:
request
- theHttpServletRequest
to useresponse
- theHttpServletResponse
to use- Returns:
- a
DeferredCsrfToken
that will load theCsrfToken
- Since:
- 5.8
-