Class ServerHttpSecurity.CsrfSpec
- java.lang.Object
-
- org.springframework.security.config.web.server.ServerHttpSecurity.CsrfSpec
-
- Enclosing class:
- ServerHttpSecurity
public final class ServerHttpSecurity.CsrfSpec extends java.lang.ObjectConfigures CSRF Protection- Since:
- 5.0
- See Also:
ServerHttpSecurity.csrf()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServerHttpSecurity.CsrfSpecaccessDeniedHandler(ServerAccessDeniedHandler accessDeniedHandler)Configures theServerAccessDeniedHandlerused when a CSRF token is invalid.ServerHttpSecurityand()Allows method chaining to continue configuring theServerHttpSecurityprotected voidconfigure(ServerHttpSecurity http)ServerHttpSecurity.CsrfSpeccsrfTokenRepository(ServerCsrfTokenRepository csrfTokenRepository)Configures theServerCsrfTokenRepositoryused to persist the CSRF Token.ServerHttpSecuritydisable()Disables CSRF Protection.ServerHttpSecurity.CsrfSpecrequireCsrfProtectionMatcher(ServerWebExchangeMatcher requireCsrfProtectionMatcher)Configures theServerWebExchangeMatcherused to determine when CSRF protection is enabled.ServerHttpSecurity.CsrfSpectokenFromMultipartDataEnabled(boolean enabled)Specifies ifCsrfWebFiltershould try to resolve the actual CSRF token from the body of multipart data requests.
-
-
-
Method Detail
-
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
-
tokenFromMultipartDataEnabled
public ServerHttpSecurity.CsrfSpec tokenFromMultipartDataEnabled(boolean enabled)
Specifies ifCsrfWebFiltershould try to resolve the actual CSRF token from the body of multipart data requests.- Parameters:
enabled- true if should read from multipart form body, else false. Default is false- Returns:
- the
ServerHttpSecurity.CsrfSpecfor additional configuration
-
and
public ServerHttpSecurity and()
Allows method chaining to continue configuring theServerHttpSecurity- Returns:
- the
ServerHttpSecurityto continue configuring
-
disable
public ServerHttpSecurity 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
protected void configure(ServerHttpSecurity http)
-
-