Class CookieServerCsrfTokenRepository
- java.lang.Object
-
- org.springframework.security.web.server.csrf.CookieServerCsrfTokenRepository
-
- All Implemented Interfaces:
ServerCsrfTokenRepository
public final class CookieServerCsrfTokenRepository extends java.lang.Object implements ServerCsrfTokenRepository
AServerCsrfTokenRepositorythat persists the CSRF token in a cookie named "XSRF-TOKEN" and reads from the header "X-XSRF-TOKEN" following the conventions of AngularJS. When using with AngularJS be sure to usewithHttpOnlyFalse().- Since:
- 5.1
-
-
Constructor Summary
Constructors Constructor Description CookieServerCsrfTokenRepository()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description reactor.core.publisher.Mono<CsrfToken>generateToken(org.springframework.web.server.ServerWebExchange exchange)Generates aCsrfTokenreactor.core.publisher.Mono<CsrfToken>loadToken(org.springframework.web.server.ServerWebExchange exchange)Loads the expectedCsrfTokenfrom theServerWebExchangereactor.core.publisher.Mono<java.lang.Void>saveToken(org.springframework.web.server.ServerWebExchange exchange, CsrfToken token)Saves theCsrfTokenusing theServerWebExchange.voidsetCookieDomain(java.lang.String cookieDomain)Sets the cookie domainvoidsetCookieHttpOnly(boolean cookieHttpOnly)Sets the HttpOnly attribute on the cookie containing the CSRF tokenvoidsetCookieName(java.lang.String cookieName)Sets the cookie namevoidsetCookiePath(java.lang.String cookiePath)Sets the cookie pathvoidsetHeaderName(java.lang.String headerName)Sets the header namevoidsetParameterName(java.lang.String parameterName)Sets the parameter namevoidsetSecure(boolean secure)Sets the cookie secure flag.static CookieServerCsrfTokenRepositorywithHttpOnlyFalse()Factory method to conveniently create an instance that hassetCookieHttpOnly(boolean)set to false.
-
-
-
Method Detail
-
withHttpOnlyFalse
public static CookieServerCsrfTokenRepository withHttpOnlyFalse()
Factory method to conveniently create an instance that hassetCookieHttpOnly(boolean)set to false.- Returns:
- an instance of CookieCsrfTokenRepository with
setCookieHttpOnly(boolean)set to false
-
generateToken
public reactor.core.publisher.Mono<CsrfToken> generateToken(org.springframework.web.server.ServerWebExchange exchange)
Description copied from interface:ServerCsrfTokenRepositoryGenerates aCsrfToken- Specified by:
generateTokenin interfaceServerCsrfTokenRepository- Parameters:
exchange- theServerWebExchangeto use- Returns:
- the
CsrfTokenthat was generated. Cannot be null.
-
saveToken
public reactor.core.publisher.Mono<java.lang.Void> saveToken(org.springframework.web.server.ServerWebExchange exchange, CsrfToken token)Description copied from interface:ServerCsrfTokenRepositorySaves theCsrfTokenusing theServerWebExchange. If theCsrfTokenis null, it is the same as deleting it.- Specified by:
saveTokenin interfaceServerCsrfTokenRepository- Parameters:
exchange- theServerWebExchangeto usetoken- theCsrfTokento save or null to delete
-
loadToken
public reactor.core.publisher.Mono<CsrfToken> loadToken(org.springframework.web.server.ServerWebExchange exchange)
Description copied from interface:ServerCsrfTokenRepositoryLoads the expectedCsrfTokenfrom theServerWebExchange- Specified by:
loadTokenin interfaceServerCsrfTokenRepository- Parameters:
exchange- theServerWebExchangeto use- Returns:
- the
CsrfTokenor null if none exists
-
setCookieHttpOnly
public void setCookieHttpOnly(boolean cookieHttpOnly)
Sets the HttpOnly attribute on the cookie containing the CSRF token- Parameters:
cookieHttpOnly- True to mark the cookie as http only. False otherwise.
-
setCookieName
public void setCookieName(java.lang.String cookieName)
Sets the cookie name- Parameters:
cookieName- The cookie name
-
setParameterName
public void setParameterName(java.lang.String parameterName)
Sets the parameter name- Parameters:
parameterName- The parameter name
-
setHeaderName
public void setHeaderName(java.lang.String headerName)
Sets the header name- Parameters:
headerName- The header name
-
setCookiePath
public void setCookiePath(java.lang.String cookiePath)
Sets the cookie path- Parameters:
cookiePath- The cookie path
-
setCookieDomain
public void setCookieDomain(java.lang.String cookieDomain)
Sets the cookie domain- Parameters:
cookieDomain- The cookie domain
-
setSecure
public void setSecure(boolean secure)
Sets the cookie secure flag. If not set, the value depends onServerHttpRequest.getSslInfo().- Parameters:
secure- The value for the secure flag- Since:
- 5.5
-
-