Class ServerHttpSecurity.CsrfSpec
java.lang.Object
org.springframework.security.config.web.server.ServerHttpSecurity.CsrfSpec
- Enclosing class:
 - ServerHttpSecurity
 
Configures CSRF
 Protection
- Since:
 - 5.0
 - See Also:
 
- 
Method Summary
Modifier and TypeMethodDescriptionaccessDeniedHandler(ServerAccessDeniedHandler accessDeniedHandler) Configures theServerAccessDeniedHandlerused when a CSRF token is invalid.and()Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0.protected voidconfigure(ServerHttpSecurity http) csrfTokenRepository(ServerCsrfTokenRepository csrfTokenRepository) Configures theServerCsrfTokenRepositoryused to persist the CSRF Token.csrfTokenRequestHandler(ServerCsrfTokenRequestHandler requestHandler) Specifies aServerCsrfTokenRequestHandlerthat is used to make theCsrfTokenavailable as an exchange attribute.disable()Disables CSRF Protection.requireCsrfProtectionMatcher(ServerWebExchangeMatcher requireCsrfProtectionMatcher) Configures theServerWebExchangeMatcherused to determine when CSRF protection is enabled. 
- 
Method Details
- 
accessDeniedHandler
public ServerHttpSecurity.CsrfSpec accessDeniedHandler(ServerAccessDeniedHandler accessDeniedHandler) Configures theServerAccessDeniedHandlerused when a CSRF token is invalid. Default is to send anHttpStatus.FORBIDDEN.- Parameters:
 accessDeniedHandler- the access denied handler.- Returns:
 - the 
ServerHttpSecurity.CsrfSpecfor additional configuration 
 - 
csrfTokenRepository
public ServerHttpSecurity.CsrfSpec csrfTokenRepository(ServerCsrfTokenRepository csrfTokenRepository) Configures theServerCsrfTokenRepositoryused to persist the CSRF Token. Default isWebSessionServerCsrfTokenRepository.- Parameters:
 csrfTokenRepository- the repository to use- Returns:
 - the 
ServerHttpSecurity.CsrfSpecfor additional configuration 
 - 
requireCsrfProtectionMatcher
public ServerHttpSecurity.CsrfSpec requireCsrfProtectionMatcher(ServerWebExchangeMatcher requireCsrfProtectionMatcher) Configures theServerWebExchangeMatcherused to determine when CSRF protection is enabled. Default is PUT, POST, DELETE requests.- Parameters:
 requireCsrfProtectionMatcher- the matcher to use- Returns:
 - the 
ServerHttpSecurity.CsrfSpecfor additional configuration 
 - 
csrfTokenRequestHandler
public ServerHttpSecurity.CsrfSpec csrfTokenRequestHandler(ServerCsrfTokenRequestHandler requestHandler) Specifies aServerCsrfTokenRequestHandlerthat is used to make theCsrfTokenavailable as an exchange attribute.- Parameters:
 requestHandler- theServerCsrfTokenRequestHandlerto use- Returns:
 - the 
ServerHttpSecurity.CsrfSpecfor additional configuration - Since:
 - 5.8
 
 - 
and
Deprecated, for removal: This API element is subject to removal in a future version.For removal in 7.0. UseServerHttpSecurity.csrf(Customizer)orcsrf(Customizer.withDefaults())to stick with defaults. See the documentation for more details.Allows method chaining to continue configuring theServerHttpSecurity- Returns:
 - the 
ServerHttpSecurityto continue configuring 
 - 
disable
Disables CSRF Protection. Disabling CSRF Protection is only recommended when the application is never used within a browser.- Returns:
 - the 
ServerHttpSecurityto continue configuring 
 - 
configure
 
 -