Skip to content

Commit 4c838b3

Browse files
committed
Rename requireCspMatcher to requestMatcher
To align with the rest of the DSL Signed-off-by: Ziqin Wang <ziqin@wangziqin.net>
1 parent bf6f1d4 commit 4c838b3

8 files changed

Lines changed: 52 additions & 52 deletions

File tree

config/src/main/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,13 +1009,13 @@ public ContentSecurityPolicyConfig nonceAttributeName(String nonceAttributeName)
10091009
* @return the {@link ContentSecurityPolicyConfig} for additional configuration
10101010
* @throws IllegalArgumentException if {@code requestMatcher} is null
10111011
* @throws IllegalStateException if a {@link RequestMatcher} is already configured
1012-
* by a previous call of this method or {@link #requireCspMatchers(String...)}
1012+
* by a previous call of this method or {@link #requestMatchers(String...)}
10131013
* @since 7.1
1014-
* @see #requireCspMatchers(String...)
1014+
* @see #requestMatchers(String...)
10151015
*/
1016-
public ContentSecurityPolicyConfig requireCspMatcher(RequestMatcher requestMatcher) {
1016+
public ContentSecurityPolicyConfig requestMatcher(RequestMatcher requestMatcher) {
10171017
Assert.notNull(requestMatcher, "RequestMatcher cannot be null");
1018-
Assert.state(this.requestMatcher == null, "RequireCspMatcher(s) is already configured");
1018+
Assert.state(this.requestMatcher == null, "RequestMatcher(s) is already configured");
10191019
this.requestMatcher = requestMatcher;
10201020
return this;
10211021
}
@@ -1030,14 +1030,14 @@ public ContentSecurityPolicyConfig requireCspMatcher(RequestMatcher requestMatch
10301030
* @throws IllegalArgumentException if any path pattern if rejected by
10311031
* {@link PathPatternRequestMatcher.Builder#matcher(String)}
10321032
* @throws IllegalStateException if a {@link RequestMatcher} is already configured
1033-
* by a previous call of this method or {@link #requireCspMatcher(RequestMatcher)}
1033+
* by a previous call of this method or {@link #requestMatcher(RequestMatcher)}
10341034
* @since 7.1
1035-
* @see #requireCspMatcher(RequestMatcher)
1035+
* @see #requestMatcher(RequestMatcher)
10361036
*/
1037-
public ContentSecurityPolicyConfig requireCspMatchers(String... pathPatterns) {
1037+
public ContentSecurityPolicyConfig requestMatchers(String... pathPatterns) {
10381038
PathPatternRequestMatcher.Builder builder = HeadersConfigurer.this.getRequestMatcherBuilder();
10391039
OrRequestMatcher matcher = new OrRequestMatcher(Arrays.stream(pathPatterns).map(builder::matcher).toList());
1040-
return this.requireCspMatcher(matcher);
1040+
return this.requestMatcher(matcher);
10411041
}
10421042

10431043
HeaderWriter getWriter() {

config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,15 +2897,15 @@ public ContentSecurityPolicySpec nonceAttributeName(String nonceAttributeName) {
28972897
* @throws IllegalArgumentException if {@code matcher} is {@code null}
28982898
* @throws IllegalStateException if a {@link ServerWebExchangeMatcher} is
28992899
* already configured by a previous call of this method or
2900-
* {@link #requireCspMatchers(String...)}
2900+
* {@link #exchangeMatchers(String...)}
29012901
* @since 7.1
2902-
* @see #requireCspMatchers(String...)
2902+
* @see #exchangeMatchers(String...)
29032903
*/
2904-
public ContentSecurityPolicySpec requireCspMatcher(ServerWebExchangeMatcher matcher) {
2904+
public ContentSecurityPolicySpec exchangeMatcher(ServerWebExchangeMatcher matcher) {
29052905
Assert.notNull(matcher, "Matcher must not be null");
29062906
// Replace the CSP writer in the list with a matcher-decorated writer
29072907
int idx = HeaderSpec.this.writers.indexOf(HeaderSpec.this.contentSecurityPolicy);
2908-
Assert.state(idx >= 0, "RequireCspMatcher(s) is already configured");
2908+
Assert.state(idx >= 0, "ExchangeMatcher(s) is already configured");
29092909
HeaderSpec.this.writers.set(idx, new ServerWebExchangeDelegatingServerHttpHeadersWriter(matcher,
29102910
HeaderSpec.this.contentSecurityPolicy));
29112911
return this;
@@ -2922,12 +2922,12 @@ public ContentSecurityPolicySpec requireCspMatcher(ServerWebExchangeMatcher matc
29222922
* {@link PathPatternParserServerWebExchangeMatcher}
29232923
* @throws IllegalStateException if a {@link ServerWebExchangeMatcher} is
29242924
* already configured by a previous call of this method or
2925-
* {@link #requireCspMatcher(ServerWebExchangeMatcher)}
2925+
* {@link #exchangeMatcher(ServerWebExchangeMatcher)}
29262926
* @since 7.1
2927-
* @see #requireCspMatcher(ServerWebExchangeMatcher)
2927+
* @see #exchangeMatcher(ServerWebExchangeMatcher)
29282928
*/
2929-
public ContentSecurityPolicySpec requireCspMatchers(String... pathPatterns) {
2930-
return this.requireCspMatcher(ServerWebExchangeMatchers.pathMatchers(pathPatterns));
2929+
public ContentSecurityPolicySpec exchangeMatchers(String... pathPatterns) {
2930+
return this.exchangeMatcher(ServerWebExchangeMatchers.pathMatchers(pathPatterns));
29312931
}
29322932

29332933
private ContentSecurityPolicySpec(String policyDirectives) {

config/src/main/kotlin/org/springframework/security/config/annotation/web/headers/ContentSecurityPolicyDsl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ class ContentSecurityPolicyDsl {
5252
* The default is to enable CSP in every response if
5353
* [org.springframework.security.config.annotation.web.HeadersDsl.contentSecurityPolicy]
5454
* is configured.
55-
* You can configure either this property or [requireCspMatchers], but not both.
55+
* You can configure either this property or [requestMatchers], but not both.
5656
* @since 7.1
57-
* @see requireCspMatchers
57+
* @see requestMatchers
5858
*/
59-
var requireCspMatcher: RequestMatcher? = null
59+
var requestMatcher: RequestMatcher? = null
6060

6161
private var requireCspPathPatterns: Array<out String>? = null
6262

@@ -65,13 +65,13 @@ class ContentSecurityPolicyDsl {
6565
* The default is to write CSP header in every response if
6666
* [org.springframework.security.config.annotation.web.HeadersDsl.contentSecurityPolicy]
6767
* is configured.
68-
* You can configure either this method or [requireCspMatcher], but not both.
68+
* You can configure either this method or [requestMatcher], but not both.
6969
* @param pathPatterns the path patterns to be matched with a
7070
* [org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher]
7171
* @since 7.1
72-
* @see requireCspMatcher
72+
* @see requestMatcher
7373
*/
74-
fun requireCspMatchers(vararg pathPatterns: String) {
74+
fun requestMatchers(vararg pathPatterns: String) {
7575
requireCspPathPatterns = pathPatterns
7676
}
7777

@@ -86,8 +86,8 @@ class ContentSecurityPolicyDsl {
8686
}
8787
}
8888
nonceAttributeName?.also(contentSecurityPolicy::nonceAttributeName)
89-
requireCspMatcher?.also(contentSecurityPolicy::requireCspMatcher)
90-
requireCspPathPatterns?.also(contentSecurityPolicy::requireCspMatchers)
89+
requestMatcher?.also(contentSecurityPolicy::requestMatcher)
90+
requireCspPathPatterns?.also(contentSecurityPolicy::requestMatchers)
9191
}
9292
}
9393
}

config/src/main/kotlin/org/springframework/security/config/web/server/ServerContentSecurityPolicyDsl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ class ServerContentSecurityPolicyDsl {
4949
* The [ServerWebExchangeMatcher] to use for determining when CSP should be applied.
5050
* The default is to enable CSP in every response if [ServerHeadersDsl.contentSecurityPolicy]
5151
* is configured.
52-
* You can configure either this property or [requireCspMatchers], but not both.
52+
* You can configure either this property or [exchangeMatchers], but not both.
5353
* @since 7.1
54-
* @see requireCspMatchers
54+
* @see exchangeMatchers
5555
*/
56-
var requireCspMatcher: ServerWebExchangeMatcher? = null
56+
var exchangeMatcher: ServerWebExchangeMatcher? = null
5757

5858
private var requireCspPathPatterns: Array<out String>? = null
5959

6060
/**
6161
* Specify the matching path patterns for determining when CSP should be applied.
6262
* The default is to enable CSP in every response if [ServerHeadersDsl.contentSecurityPolicy]
6363
* is configured.
64-
* You can configure either this method or [requireCspMatcher], but not both.
64+
* You can configure either this method or [exchangeMatcher], but not both.
6565
* @param pathPatterns the path patterns to be matched with a
6666
* [org.springframework.security.web.server.util.matcher.PathPatternParserServerWebExchangeMatcher]
6767
* @since 7.1
68-
* @see requireCspMatcher
68+
* @see exchangeMatcher
6969
*/
70-
fun requireCspMatchers(vararg pathPatterns: String) {
70+
fun exchangeMatchers(vararg pathPatterns: String) {
7171
requireCspPathPatterns = pathPatterns
7272
}
7373

@@ -80,8 +80,8 @@ class ServerContentSecurityPolicyDsl {
8080
contentSecurityPolicy.reportOnly(reportOnly!!)
8181
}
8282
nonceAttributeName?.also(contentSecurityPolicy::nonceAttributeName)
83-
requireCspMatcher?.also(contentSecurityPolicy::requireCspMatcher)
84-
requireCspPathPatterns?.also(contentSecurityPolicy::requireCspMatchers)
83+
exchangeMatcher?.also(contentSecurityPolicy::exchangeMatcher)
84+
requireCspPathPatterns?.also(contentSecurityPolicy::exchangeMatchers)
8585
}
8686
}
8787
}

config/src/test/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurerTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public void configureWhenContentSecurityPolicyWithOverriddenMatchersThenThrows()
486486
.isThrownBy(() -> this.spring.register(ContentSecurityPolicyOverriddenMatchersConfig.class).autowire())
487487
.havingRootCause()
488488
.isInstanceOf(IllegalStateException.class)
489-
.withMessage("RequireCspMatcher(s) is already configured");
489+
.withMessage("RequestMatcher(s) is already configured");
490490
}
491491

492492
@Test
@@ -1246,7 +1246,7 @@ SecurityFilterChain filterChain(HttpSecurity http) {
12461246
.defaultsDisabled()
12471247
.contentSecurityPolicy((csp) -> csp
12481248
.policyDirectives("default-src 'self'")
1249-
.requireCspMatcher((request) -> {
1249+
.requestMatcher((request) -> {
12501250
var accepted = MediaType.parseMediaTypes(request.getHeader(HttpHeaders.ACCEPT));
12511251
return MediaType.TEXT_HTML.isPresentIn(accepted);
12521252
})));
@@ -1268,7 +1268,7 @@ SecurityFilterChain filterChain(HttpSecurity http) {
12681268
.defaultsDisabled()
12691269
.contentSecurityPolicy((csp) -> csp
12701270
.policyDirectives("default-src 'self'")
1271-
.requireCspMatchers("/foo/**", "/bar/**")));
1271+
.requestMatchers("/foo/**", "/bar/**")));
12721272
// @formatter:on
12731273
return http.build();
12741274
}
@@ -1287,8 +1287,8 @@ SecurityFilterChain filterChain(HttpSecurity http) {
12871287
.defaultsDisabled()
12881288
.contentSecurityPolicy((csp) -> csp
12891289
.policyDirectives("default-src 'self'")
1290-
.requireCspMatcher(AnyRequestMatcher.INSTANCE)
1291-
.requireCspMatchers("/**")));
1290+
.requestMatcher(AnyRequestMatcher.INSTANCE)
1291+
.requestMatchers("/**")));
12921292
// @formatter:on
12931293
return http.build();
12941294
}

config/src/test/java/org/springframework/security/config/web/server/HeaderSpecTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public void headersWhenContentSecurityPolicyEnabledWithMatcherThenHeaderInRespon
463463
// @formatter:off
464464
this.http.headers((headers) -> headers
465465
.contentSecurityPolicy((csp) -> csp
466-
.requireCspMatcher((exchange) ->
466+
.exchangeMatcher((exchange) ->
467467
(MediaType.TEXT_HTML.isPresentIn(exchange.getRequest().getHeaders().getAccept()) ?
468468
ServerWebExchangeMatcher.MatchResult.match() :
469469
ServerWebExchangeMatcher.MatchResult.notMatch()))
@@ -491,7 +491,7 @@ public void headersWhenContentSecurityPolicyEnabledWithPathMatchersThenHeaderInR
491491
// @formatter:off
492492
this.http.headers((headers) -> headers
493493
.contentSecurityPolicy((csp) -> csp
494-
.requireCspMatchers("/foo/**", "/bar/**")
494+
.exchangeMatchers("/foo/**", "/bar/**")
495495
.policyDirectives(policyDirectives)));
496496
// @formatter:on
497497
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.http.build()).build();
@@ -518,10 +518,10 @@ public void headersWhenContentSecurityPolicyWithOverriddenMatchersThenFailToConf
518518
.isThrownBy(() -> this.http
519519
.headers((headers) -> headers
520520
.contentSecurityPolicy((csp) -> csp
521-
.requireCspMatcher(ServerWebExchangeMatchers.anyExchange())
522-
.requireCspMatchers("/**")
521+
.exchangeMatcher(ServerWebExchangeMatchers.anyExchange())
522+
.exchangeMatchers("/**")
523523
.policyDirectives("default-src 'self'"))))
524-
.withMessage("RequireCspMatcher(s) is already configured");
524+
.withMessage("ExchangeMatcher(s) is already configured");
525525
// @formatter:on
526526
}
527527

config/src/test/kotlin/org/springframework/security/config/annotation/web/headers/ContentSecurityPolicyDslTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class ContentSecurityPolicyDslTests {
233233
defaultsDisabled = true
234234
contentSecurityPolicy {
235235
policyDirectives = "default-src 'self'"
236-
requireCspMatcher = RequestMatcher { request ->
236+
requestMatcher = RequestMatcher { request ->
237237
val accepted = MediaType.parseMediaTypes(request.getHeader(HttpHeaders.ACCEPT))
238238
MediaType.TEXT_HTML.isPresentIn(accepted)
239239
}
@@ -281,7 +281,7 @@ class ContentSecurityPolicyDslTests {
281281
defaultsDisabled = true
282282
contentSecurityPolicy {
283283
policyDirectives = "default-src 'self'"
284-
requireCspMatchers("/foo/**", "/bar/**")
284+
requestMatchers("/foo/**", "/bar/**")
285285
}
286286
}
287287
}
@@ -294,7 +294,7 @@ class ContentSecurityPolicyDslTests {
294294
assertThatThrownBy {
295295
this.spring.register(ContentSecurityPolicyOverriddenMatchersConfig::class.java).autowire()
296296
}.hasRootCauseInstanceOf(IllegalStateException::class.java)
297-
.hasRootCauseMessage("RequireCspMatcher(s) is already configured")
297+
.hasRootCauseMessage("RequestMatcher(s) is already configured")
298298
}
299299

300300
@Configuration
@@ -307,8 +307,8 @@ class ContentSecurityPolicyDslTests {
307307
defaultsDisabled = true
308308
contentSecurityPolicy {
309309
policyDirectives = "default-src 'self'"
310-
requireCspMatcher = AnyRequestMatcher.INSTANCE
311-
requireCspMatchers("/**")
310+
requestMatcher = AnyRequestMatcher.INSTANCE
311+
requestMatchers("/**")
312312
}
313313
}
314314
}

config/src/test/kotlin/org/springframework/security/config/web/server/ServerContentSecurityPolicyDslTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ServerContentSecurityPolicyDslTests {
212212
headers {
213213
contentSecurityPolicy {
214214
policyDirectives = "default-src 'self'"
215-
requireCspMatcher = ServerWebExchangeMatcher { exchange ->
215+
exchangeMatcher = ServerWebExchangeMatcher { exchange ->
216216
if (MediaType.TEXT_HTML.isPresentIn(exchange.request.headers.accept))
217217
ServerWebExchangeMatcher.MatchResult.match()
218218
else
@@ -251,7 +251,7 @@ class ServerContentSecurityPolicyDslTests {
251251
headers {
252252
contentSecurityPolicy {
253253
policyDirectives = "default-src 'self'"
254-
requireCspMatchers("/foo/**", "/bar/**")
254+
exchangeMatchers("/foo/**", "/bar/**")
255255
}
256256
}
257257
}
@@ -262,7 +262,7 @@ class ServerContentSecurityPolicyDslTests {
262262
assertThatThrownBy {
263263
this.spring.register(CspPathOverriddenMatchersConfig::class.java).autowire()
264264
}.hasRootCauseInstanceOf(IllegalStateException::class.java)
265-
.hasRootCauseMessage("RequireCspMatcher(s) is already configured")
265+
.hasRootCauseMessage("ExchangeMatcher(s) is already configured")
266266
}
267267

268268
@Configuration
@@ -274,8 +274,8 @@ class ServerContentSecurityPolicyDslTests {
274274
headers {
275275
contentSecurityPolicy {
276276
policyDirectives = "default-src 'self'"
277-
requireCspMatcher = ServerWebExchangeMatchers.anyExchange()
278-
requireCspMatchers("/**")
277+
exchangeMatcher = ServerWebExchangeMatchers.anyExchange()
278+
exchangeMatchers("/**")
279279
}
280280
}
281281
}

0 commit comments

Comments
 (0)