@@ -3377,12 +3377,12 @@ public HttpSecurity requestMatcher(RequestMatcher requestMatcher) {
3377
3377
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
3378
3378
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
3379
3379
* 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)}.
3381
3381
*
3382
3382
* <p>
3383
3383
* Invoking {@link #securityMatchers()} will not override previous invocations of
3384
3384
* {@link #securityMatchers()}}, {@link #securityMatchers(Customizer)}
3385
- * {@link #securityMatcher(String)} and {@link #securityMatcher(RequestMatcher)}
3385
+ * {@link #securityMatcher(String... )} and {@link #securityMatcher(RequestMatcher)}
3386
3386
* </p>
3387
3387
*
3388
3388
* <h3>Example Configurations</h3>
@@ -3498,12 +3498,12 @@ public RequestMatcherConfigurer securityMatchers() {
3498
3498
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
3499
3499
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
3500
3500
* 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)}.
3502
3502
*
3503
3503
* <p>
3504
3504
* Invoking {@link #securityMatchers(Customizer)} will not override previous
3505
3505
* invocations of {@link #securityMatchers()}}, {@link #securityMatchers(Customizer)}
3506
- * {@link #securityMatcher(String)} and {@link #securityMatcher(RequestMatcher)}
3506
+ * {@link #securityMatcher(String... )} and {@link #securityMatcher(RequestMatcher)}
3507
3507
* </p>
3508
3508
*
3509
3509
* <h3>Example Configurations</h3>
@@ -3627,12 +3627,12 @@ public HttpSecurity securityMatchers(Customizer<RequestMatcherConfigurer> reques
3627
3627
* invocations of {@link #requestMatchers()}, {@link #mvcMatcher(String)},
3628
3628
* {@link #antMatcher(String)}, {@link #regexMatcher(String)},
3629
3629
* {@link #requestMatcher(RequestMatcher)}, {@link #securityMatchers(Customizer)},
3630
- * {@link #securityMatchers()} and {@link #securityMatcher(String)}
3630
+ * {@link #securityMatchers()} and {@link #securityMatcher(String... )}
3631
3631
* </p>
3632
3632
* @param requestMatcher the {@link RequestMatcher} to use (i.e. new
3633
3633
* AntPathRequestMatcher("/admin/**","GET") )
3634
3634
* @return the {@link HttpSecurity} for further customizations
3635
- * @see #securityMatcher(String)
3635
+ * @see #securityMatcher(String... )
3636
3636
*/
3637
3637
public HttpSecurity securityMatcher (RequestMatcher requestMatcher ) {
3638
3638
this .requestMatcher = requestMatcher ;
@@ -3647,30 +3647,49 @@ public HttpSecurity securityMatcher(RequestMatcher requestMatcher) {
3647
3647
* {@link #securityMatchers(Customizer)} or {@link #securityMatcher(RequestMatcher)}.
3648
3648
*
3649
3649
* <p>
3650
- * Invoking {@link #securityMatcher(String)} will override previous invocations of
3650
+ * Invoking {@link #securityMatcher(String... )} will override previous invocations of
3651
3651
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
3652
3652
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
3653
3653
* {@link #requestMatcher(RequestMatcher)}.
3654
3654
* </p>
3655
- * @param pattern the pattern to match on (i.e. "/admin/**")
3655
+ * @param patterns the pattern to match on (i.e. "/admin/**")
3656
3656
* @return the {@link HttpSecurity} for further customizations
3657
3657
* @see AntPathRequestMatcher
3658
3658
* @see MvcRequestMatcher
3659
3659
*/
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 ) );
3663
3663
return this ;
3664
3664
}
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 );
3665
3679
if (!getContext ().containsBean (HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME )) {
3666
3680
throw new NoSuchBeanDefinitionException ("A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME
3667
3681
+ " of type " + HandlerMappingIntrospector .class .getName ()
3668
3682
+ " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext." );
3669
3683
}
3670
3684
HandlerMappingIntrospector introspector = getContext ().getBean (HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME ,
3671
3685
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 ;
3674
3693
}
3675
3694
3676
3695
/**
@@ -3686,7 +3705,7 @@ public HttpSecurity securityMatcher(String pattern) {
3686
3705
* </p>
3687
3706
* @param antPattern the Ant Pattern to match on (i.e. "/admin/**")
3688
3707
* @return the {@link HttpSecurity} for further customizations
3689
- * @deprecated use {@link #securityMatcher(String)} instead
3708
+ * @deprecated use {@link #securityMatcher(String... )} instead
3690
3709
* @see AntPathRequestMatcher
3691
3710
*/
3692
3711
@ Deprecated
@@ -3707,7 +3726,7 @@ public HttpSecurity antMatcher(String antPattern) {
3707
3726
* </p>
3708
3727
* @param mvcPattern the Spring MVC Pattern to match on (i.e. "/admin/**")
3709
3728
* @return the {@link HttpSecurity} for further customizations
3710
- * @deprecated use {@link #securityMatcher(String)} instead
3729
+ * @deprecated use {@link #securityMatcher(String... )} instead
3711
3730
* @see MvcRequestMatcher
3712
3731
*/
3713
3732
@ Deprecated
0 commit comments