Skip to content

Commit 22ba358

Browse files
Merge branch '5.8.x'
2 parents 38a7bbd + bf6e85e commit 22ba358

File tree

1 file changed

+34
-15
lines changed
  • config/src/main/java/org/springframework/security/config/annotation/web/builders

1 file changed

+34
-15
lines changed

Diff for: config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java

+34-15
Original file line numberDiff line numberDiff line change
@@ -3377,12 +3377,12 @@ public HttpSecurity requestMatcher(RequestMatcher requestMatcher) {
33773377
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
33783378
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
33793379
* only a single {@link RequestMatcher} is necessary consider using
3380-
* {@link #securityMatcher(String)}, or {@link #securityMatcher(RequestMatcher)}.
3380+
* {@link #securityMatcher(String...)}, or {@link #securityMatcher(RequestMatcher)}.
33813381
*
33823382
* <p>
33833383
* Invoking {@link #securityMatchers()} will not override previous invocations of
33843384
* {@link #securityMatchers()}}, {@link #securityMatchers(Customizer)}
3385-
* {@link #securityMatcher(String)} and {@link #securityMatcher(RequestMatcher)}
3385+
* {@link #securityMatcher(String...)} and {@link #securityMatcher(RequestMatcher)}
33863386
* </p>
33873387
*
33883388
* <h3>Example Configurations</h3>
@@ -3498,12 +3498,12 @@ public RequestMatcherConfigurer securityMatchers() {
34983498
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
34993499
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
35003500
* only a single {@link RequestMatcher} is necessary consider using
3501-
* {@link #securityMatcher(String)}, or {@link #securityMatcher(RequestMatcher)}.
3501+
* {@link #securityMatcher(String...)}, or {@link #securityMatcher(RequestMatcher)}.
35023502
*
35033503
* <p>
35043504
* Invoking {@link #securityMatchers(Customizer)} will not override previous
35053505
* invocations of {@link #securityMatchers()}}, {@link #securityMatchers(Customizer)}
3506-
* {@link #securityMatcher(String)} and {@link #securityMatcher(RequestMatcher)}
3506+
* {@link #securityMatcher(String...)} and {@link #securityMatcher(RequestMatcher)}
35073507
* </p>
35083508
*
35093509
* <h3>Example Configurations</h3>
@@ -3627,12 +3627,12 @@ public HttpSecurity securityMatchers(Customizer<RequestMatcherConfigurer> reques
36273627
* invocations of {@link #requestMatchers()}, {@link #mvcMatcher(String)},
36283628
* {@link #antMatcher(String)}, {@link #regexMatcher(String)},
36293629
* {@link #requestMatcher(RequestMatcher)}, {@link #securityMatchers(Customizer)},
3630-
* {@link #securityMatchers()} and {@link #securityMatcher(String)}
3630+
* {@link #securityMatchers()} and {@link #securityMatcher(String...)}
36313631
* </p>
36323632
* @param requestMatcher the {@link RequestMatcher} to use (i.e. new
36333633
* AntPathRequestMatcher("/admin/**","GET") )
36343634
* @return the {@link HttpSecurity} for further customizations
3635-
* @see #securityMatcher(String)
3635+
* @see #securityMatcher(String...)
36363636
*/
36373637
public HttpSecurity securityMatcher(RequestMatcher requestMatcher) {
36383638
this.requestMatcher = requestMatcher;
@@ -3647,30 +3647,49 @@ public HttpSecurity securityMatcher(RequestMatcher requestMatcher) {
36473647
* {@link #securityMatchers(Customizer)} or {@link #securityMatcher(RequestMatcher)}.
36483648
*
36493649
* <p>
3650-
* Invoking {@link #securityMatcher(String)} will override previous invocations of
3650+
* Invoking {@link #securityMatcher(String...)} will override previous invocations of
36513651
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
36523652
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
36533653
* {@link #requestMatcher(RequestMatcher)}.
36543654
* </p>
3655-
* @param pattern the pattern to match on (i.e. "/admin/**")
3655+
* @param patterns the pattern to match on (i.e. "/admin/**")
36563656
* @return the {@link HttpSecurity} for further customizations
36573657
* @see AntPathRequestMatcher
36583658
* @see MvcRequestMatcher
36593659
*/
3660-
public HttpSecurity securityMatcher(String pattern) {
3661-
if (!mvcPresent) {
3662-
this.requestMatcher = new AntPathRequestMatcher(pattern);
3660+
public HttpSecurity securityMatcher(String... patterns) {
3661+
if (mvcPresent) {
3662+
this.requestMatcher = new OrRequestMatcher(createMvcMatchers(patterns));
36633663
return this;
36643664
}
3665+
this.requestMatcher = new OrRequestMatcher(createAntMatchers(patterns));
3666+
return this;
3667+
}
3668+
3669+
private List<RequestMatcher> createAntMatchers(String... patterns) {
3670+
List<RequestMatcher> matchers = new ArrayList<>(patterns.length);
3671+
for (String pattern : patterns) {
3672+
matchers.add(new AntPathRequestMatcher(pattern));
3673+
}
3674+
return matchers;
3675+
}
3676+
3677+
private List<RequestMatcher> createMvcMatchers(String... mvcPatterns) {
3678+
ObjectPostProcessor<Object> opp = getContext().getBean(ObjectPostProcessor.class);
36653679
if (!getContext().containsBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) {
36663680
throw new NoSuchBeanDefinitionException("A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME
36673681
+ " of type " + HandlerMappingIntrospector.class.getName()
36683682
+ " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.");
36693683
}
36703684
HandlerMappingIntrospector introspector = getContext().getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME,
36713685
HandlerMappingIntrospector.class);
3672-
this.requestMatcher = new MvcRequestMatcher(introspector, pattern);
3673-
return this;
3686+
List<RequestMatcher> matchers = new ArrayList<>(mvcPatterns.length);
3687+
for (String mvcPattern : mvcPatterns) {
3688+
MvcRequestMatcher matcher = new MvcRequestMatcher(introspector, mvcPattern);
3689+
opp.postProcess(matcher);
3690+
matchers.add(matcher);
3691+
}
3692+
return matchers;
36743693
}
36753694

36763695
/**
@@ -3686,7 +3705,7 @@ public HttpSecurity securityMatcher(String pattern) {
36863705
* </p>
36873706
* @param antPattern the Ant Pattern to match on (i.e. "/admin/**")
36883707
* @return the {@link HttpSecurity} for further customizations
3689-
* @deprecated use {@link #securityMatcher(String)} instead
3708+
* @deprecated use {@link #securityMatcher(String...)} instead
36903709
* @see AntPathRequestMatcher
36913710
*/
36923711
@Deprecated
@@ -3707,7 +3726,7 @@ public HttpSecurity antMatcher(String antPattern) {
37073726
* </p>
37083727
* @param mvcPattern the Spring MVC Pattern to match on (i.e. "/admin/**")
37093728
* @return the {@link HttpSecurity} for further customizations
3710-
* @deprecated use {@link #securityMatcher(String)} instead
3729+
* @deprecated use {@link #securityMatcher(String...)} instead
37113730
* @see MvcRequestMatcher
37123731
*/
37133732
@Deprecated

0 commit comments

Comments
 (0)