Interface CsrfTokenRepository
-
- All Known Implementing Classes:
CookieCsrfTokenRepository
,HttpSessionCsrfTokenRepository
,LazyCsrfTokenRepository
public interface CsrfTokenRepository
An API to allow changing the method in which the expectedCsrfToken
is associated to theHttpServletRequest
. For example, it may be stored inHttpSession
.- Since:
- 3.2
- See Also:
HttpSessionCsrfTokenRepository
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CsrfToken
generateToken(javax.servlet.http.HttpServletRequest request)
Generates aCsrfToken
default DeferredCsrfToken
loadDeferredToken(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Defers loading theCsrfToken
using theHttpServletRequest
andHttpServletResponse
until it is needed by the application.CsrfToken
loadToken(javax.servlet.http.HttpServletRequest request)
Loads the expectedCsrfToken
from theHttpServletRequest
void
saveToken(CsrfToken token, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
-
-
Method Detail
-
generateToken
CsrfToken generateToken(javax.servlet.http.HttpServletRequest request)
Generates aCsrfToken
- Parameters:
request
- theHttpServletRequest
to use- Returns:
- the
CsrfToken
that was generated. Cannot be null.
-
saveToken
void saveToken(CsrfToken token, javax.servlet.http.HttpServletRequest request, javax.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
CsrfToken loadToken(javax.servlet.http.HttpServletRequest request)
Loads the expectedCsrfToken
from theHttpServletRequest
- Parameters:
request
- theHttpServletRequest
to use- Returns:
- the
CsrfToken
or null if none exists
-
loadDeferredToken
default DeferredCsrfToken loadDeferredToken(javax.servlet.http.HttpServletRequest request, javax.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
-
-