Package org.forgerock.http.filter
Class CsrfFilter.Builder
java.lang.Object
org.forgerock.http.filter.CsrfFilter.Builder
- Enclosing class:
- CsrfFilter
Builder class for the CSRF filter.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the CSRF filter with the configured settings.excludeMethods(String... httpMethods) Excludes a HTTP method from the CSRF filter.excludePaths(String... paths) Excludes a path from the CSRF filter.excludePaths(Collection<String> paths) Excludes the paths from the CSRF filter.excludePathsStarting(String... pathPrefixes) Excludes paths starting with the given prefixes from the CSRF filter.excludePathsStarting(Collection<String> pathPrefixes) Excludes paths starting with the given prefixes from the CSRF filter.excludeRequests(Predicate<Request> predicate) Excludes requests that match the given predicate from the CSRF filter.excludeRequests(Predicate<Request> predicate, String description) Excludes requests that match the given predicate from the CSRF filter.Excludes HTTP safe methods that are usually not susceptible to CSRF attacks:GET,HEAD, andOPTIONS.failureHandler(Handler failureHandler) Add a handler which will be responsible of creating a response in case of missing/wrong CSRF token.tokenHeader(String csrfTokenHeader) Sets the header to use to receive the anti-CSRF token.toString()
-
Method Details
-
tokenHeader
Sets the header to use to receive the anti-CSRF token. This header will be used by clients to send the CSRF token on requests and will be used on responses to communicate the correct CSRF token to legitimate clients. Defaults to "X-CSRF-Token".- Parameters:
csrfTokenHeader- the header to use for the CSRF token.- Returns:
- this builder
-
excludeRequests
Excludes requests that match the given predicate from the CSRF filter. Requests that match the predicate will be allowed even if they don't have a valid CSRF token.- Parameters:
predicate- the predicate to test the request.- Returns:
- this builder
-
excludeRequests
Excludes requests that match the given predicate from the CSRF filter. Requests that match the predicate will be allowed even if they don't have a valid CSRF token.- Parameters:
predicate- the predicate to test the request.description- a description for the predicate used in debug logging.- Returns:
- this builder
-
excludeMethods
Excludes a HTTP method from the CSRF filter. Requests using any of these methods will be allowed to continue without performing any CSRF checks. By default all methods are required to include the CSRF token. Method names are case insensitive.- Parameters:
httpMethods- http methods to exclude from the CSRF filter checks.- Returns:
- this builder
-
excludeSafeMethods
Excludes HTTP safe methods that are usually not susceptible to CSRF attacks:GET,HEAD, andOPTIONS. Note: we do not excludeTRACEmethods by default due to the risk of Cross-Site Tracing.- Returns:
- this builder.
-
excludePaths
Excludes a path from the CSRF filter. Path comparison is case-sensitive exact matching only.- Parameters:
paths- the paths to exclude from the CSRF filter.- Returns:
- this builder.
-
excludePaths
Excludes the paths from the CSRF filter. Path comparison is case-sensitive exact matching only.- Parameters:
paths- the paths to exclude from the CSRF filter.- Returns:
- this builder.
-
excludePathsStarting
Excludes paths starting with the given prefixes from the CSRF filter. Each path prefix is compared case-sensitively.- Parameters:
pathPrefixes- the path prefixes to exclude from the CSRF filter.- Returns:
- this builder.
-
excludePathsStarting
Excludes paths starting with the given prefixes from the CSRF filter. Each path prefix is compared case-sensitively.- Parameters:
pathPrefixes- the path prefixes to exclude from the CSRF filter.- Returns:
- this builder.
-
failureHandler
Add a handler which will be responsible of creating a response in case of missing/wrong CSRF token.- Parameters:
failureHandler- the handler to call in case of CSRF filter failure.- Returns:
- this builder.
-
build
Builds the CSRF filter with the configured settings.- Returns:
- the configured CSRF filter.
-
toString
-