Class LazyCsrfTokenRepository
- java.lang.Object
-
- org.springframework.security.web.csrf.LazyCsrfTokenRepository
-
- All Implemented Interfaces:
CsrfTokenRepository
public final class LazyCsrfTokenRepository extends java.lang.Object implements CsrfTokenRepository
ACsrfTokenRepositorythat delays saving newCsrfTokenuntil the attributes of theCsrfTokenthat were generated are accessed.- Since:
- 4.1
-
-
Constructor Summary
Constructors Constructor Description LazyCsrfTokenRepository(CsrfTokenRepository delegate)Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CsrfTokengenerateToken(javax.servlet.http.HttpServletRequest request)Generates a new tokenCsrfTokenloadToken(javax.servlet.http.HttpServletRequest request)Delegates to the injectedCsrfTokenRepositoryvoidsaveToken(CsrfToken token, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Does nothing if theCsrfTokenis not null.
-
-
-
Constructor Detail
-
LazyCsrfTokenRepository
public LazyCsrfTokenRepository(CsrfTokenRepository delegate)
Creates a new instance- Parameters:
delegate- theCsrfTokenRepositoryto use. Cannot be null- Throws:
java.lang.IllegalArgumentException- if delegate is null.
-
-
Method Detail
-
generateToken
public CsrfToken generateToken(javax.servlet.http.HttpServletRequest request)
Generates a new token- Specified by:
generateTokenin interfaceCsrfTokenRepository- Parameters:
request- theHttpServletRequestto use. TheHttpServletRequestmust have theHttpServletResponseas an attribute with the name ofHttpServletResponse.class.getName()- Returns:
- the
CsrfTokenthat was generated. Cannot be null.
-
saveToken
public void saveToken(CsrfToken token, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Does nothing if theCsrfTokenis not null. Saving is done only when theCsrfToken.getToken()is accessed fromgenerateToken(HttpServletRequest). If it is null, then the save is performed immediately.- Specified by:
saveTokenin interfaceCsrfTokenRepository- Parameters:
token- theCsrfTokento save or null to deleterequest- theHttpServletRequestto useresponse- theHttpServletResponseto use
-
loadToken
public CsrfToken loadToken(javax.servlet.http.HttpServletRequest request)
Delegates to the injectedCsrfTokenRepository- Specified by:
loadTokenin interfaceCsrfTokenRepository- Parameters:
request- theHttpServletRequestto use- Returns:
- the
CsrfTokenor null if none exists
-
-