Skip to content

Commit 85c9d8f

Browse files
committed
Document behavior with multiple CorsConfigurationSource beans
Clarify that Spring Security fails with an ambiguous bean definition error when multiple CorsConfigurationSource beans are present, and refer users to the per-chain configuration section for the solution. Closes gh-18583 Signed-off-by: hanweiwei <duzielww@163.com> Signed-off-by: hanweiwei <duzielww@163.com>
1 parent 1455798 commit 85c9d8f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

docs/modules/ROOT/pages/reactive/integrations/cors.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ If the request does not contain any cookies and Spring Security is first, the re
77

88
The easiest way to ensure that CORS is handled first is to use the `CorsWebFilter`.
99
Users can integrate the `CorsWebFilter` with Spring Security by providing a `CorsConfigurationSource`.
10+
11+
NOTE: If multiple `CorsConfigurationSource` beans are defined in the application context, Spring Security will not automatically select one and will fail with an ambiguous bean definition error.
12+
In that case, you should specify which `CorsConfigurationSource` to use for each security filter chain by passing it directly to the `.cors()` DSL.
13+
1014
For example, the following will integrate CORS support within Spring Security:
1115

1216
[tabs]

docs/modules/ROOT/pages/servlet/integrations/cors.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ If the request does not contain any cookies and Spring Security is first, the re
1010

1111
The easiest way to ensure that CORS is handled first is to use the `CorsFilter`.
1212
Users can integrate the `CorsFilter` with Spring Security by providing a `CorsConfigurationSource`.
13-
Note that Spring Security will automatically configure CORS only if a `UrlBasedCorsConfigurationSource` instance is present.
13+
Note that Spring Security will automatically configure CORS only if a single `UrlBasedCorsConfigurationSource` instance is present.
14+
If multiple `CorsConfigurationSource` beans are defined in the application context, Spring Security will not automatically select one and will fail with an ambiguous bean definition error.
15+
In that case, you should specify which `CorsConfigurationSource` to use for each `SecurityFilterChain` by passing it directly to the `.cors()` DSL as shown in the <<cors-per-chain-configuration>> section.
16+
1417
For example, the following will integrate CORS support within Spring Security:
1518

1619
[tabs]

0 commit comments

Comments
 (0)