@@ -3599,12 +3599,12 @@ public HttpSecurity requestMatcher(RequestMatcher requestMatcher) {
3599
3599
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
3600
3600
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
3601
3601
* only a single {@link RequestMatcher} is necessary consider using
3602
- * {@link #securityMatcher(String)}, or {@link #securityMatcher(RequestMatcher)}.
3602
+ * {@link #securityMatcher(String... )}, or {@link #securityMatcher(RequestMatcher)}.
3603
3603
*
3604
3604
* <p>
3605
3605
* Invoking {@link #securityMatchers()} will not override previous invocations of
3606
3606
* {@link #securityMatchers()}}, {@link #securityMatchers(Customizer)}
3607
- * {@link #securityMatcher(String)} and {@link #securityMatcher(RequestMatcher)}
3607
+ * {@link #securityMatcher(String... )} and {@link #securityMatcher(RequestMatcher)}
3608
3608
* </p>
3609
3609
*
3610
3610
* <h3>Example Configurations</h3>
@@ -3720,12 +3720,12 @@ public RequestMatcherConfigurer securityMatchers() {
3720
3720
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
3721
3721
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
3722
3722
* only a single {@link RequestMatcher} is necessary consider using
3723
- * {@link #securityMatcher(String)}, or {@link #securityMatcher(RequestMatcher)}.
3723
+ * {@link #securityMatcher(String... )}, or {@link #securityMatcher(RequestMatcher)}.
3724
3724
*
3725
3725
* <p>
3726
3726
* Invoking {@link #securityMatchers(Customizer)} will not override previous
3727
3727
* invocations of {@link #securityMatchers()}}, {@link #securityMatchers(Customizer)}
3728
- * {@link #securityMatcher(String)} and {@link #securityMatcher(RequestMatcher)}
3728
+ * {@link #securityMatcher(String... )} and {@link #securityMatcher(RequestMatcher)}
3729
3729
* </p>
3730
3730
*
3731
3731
* <h3>Example Configurations</h3>
@@ -3849,12 +3849,12 @@ public HttpSecurity securityMatchers(Customizer<RequestMatcherConfigurer> reques
3849
3849
* invocations of {@link #requestMatchers()}, {@link #mvcMatcher(String)},
3850
3850
* {@link #antMatcher(String)}, {@link #regexMatcher(String)},
3851
3851
* {@link #requestMatcher(RequestMatcher)}, {@link #securityMatchers(Customizer)},
3852
- * {@link #securityMatchers()} and {@link #securityMatcher(String)}
3852
+ * {@link #securityMatchers()} and {@link #securityMatcher(String... )}
3853
3853
* </p>
3854
3854
* @param requestMatcher the {@link RequestMatcher} to use (i.e. new
3855
3855
* AntPathRequestMatcher("/admin/**","GET") )
3856
3856
* @return the {@link HttpSecurity} for further customizations
3857
- * @see #securityMatcher(String)
3857
+ * @see #securityMatcher(String... )
3858
3858
*/
3859
3859
public HttpSecurity securityMatcher (RequestMatcher requestMatcher ) {
3860
3860
this .requestMatcher = requestMatcher ;
@@ -3869,30 +3869,49 @@ public HttpSecurity securityMatcher(RequestMatcher requestMatcher) {
3869
3869
* {@link #securityMatchers(Customizer)} or {@link #securityMatcher(RequestMatcher)}.
3870
3870
*
3871
3871
* <p>
3872
- * Invoking {@link #securityMatcher(String)} will override previous invocations of
3872
+ * Invoking {@link #securityMatcher(String... )} will override previous invocations of
3873
3873
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
3874
3874
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
3875
3875
* {@link #requestMatcher(RequestMatcher)}.
3876
3876
* </p>
3877
- * @param pattern the pattern to match on (i.e. "/admin/**")
3877
+ * @param patterns the pattern to match on (i.e. "/admin/**")
3878
3878
* @return the {@link HttpSecurity} for further customizations
3879
3879
* @see AntPathRequestMatcher
3880
3880
* @see MvcRequestMatcher
3881
3881
*/
3882
- public HttpSecurity securityMatcher (String pattern ) {
3883
- if (! mvcPresent ) {
3884
- this .requestMatcher = new AntPathRequestMatcher ( pattern );
3882
+ public HttpSecurity securityMatcher (String ... patterns ) {
3883
+ if (mvcPresent ) {
3884
+ this .requestMatcher = new OrRequestMatcher ( createMvcMatchers ( patterns ) );
3885
3885
return this ;
3886
3886
}
3887
+ this .requestMatcher = new OrRequestMatcher (createAntMatchers (patterns ));
3888
+ return this ;
3889
+ }
3890
+
3891
+ private List <RequestMatcher > createAntMatchers (String ... patterns ) {
3892
+ List <RequestMatcher > matchers = new ArrayList <>(patterns .length );
3893
+ for (String pattern : patterns ) {
3894
+ matchers .add (new AntPathRequestMatcher (pattern ));
3895
+ }
3896
+ return matchers ;
3897
+ }
3898
+
3899
+ private List <RequestMatcher > createMvcMatchers (String ... mvcPatterns ) {
3900
+ ObjectPostProcessor <Object > opp = getContext ().getBean (ObjectPostProcessor .class );
3887
3901
if (!getContext ().containsBean (HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME )) {
3888
3902
throw new NoSuchBeanDefinitionException ("A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME
3889
3903
+ " of type " + HandlerMappingIntrospector .class .getName ()
3890
3904
+ " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext." );
3891
3905
}
3892
3906
HandlerMappingIntrospector introspector = getContext ().getBean (HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME ,
3893
3907
HandlerMappingIntrospector .class );
3894
- this .requestMatcher = new MvcRequestMatcher (introspector , pattern );
3895
- return this ;
3908
+ List <RequestMatcher > matchers = new ArrayList <>(mvcPatterns .length );
3909
+ for (String mvcPattern : mvcPatterns ) {
3910
+ MvcRequestMatcher matcher = new MvcRequestMatcher (introspector , mvcPattern );
3911
+ opp .postProcess (matcher );
3912
+ matchers .add (matcher );
3913
+ }
3914
+ return matchers ;
3896
3915
}
3897
3916
3898
3917
/**
@@ -3908,7 +3927,7 @@ public HttpSecurity securityMatcher(String pattern) {
3908
3927
* </p>
3909
3928
* @param antPattern the Ant Pattern to match on (i.e. "/admin/**")
3910
3929
* @return the {@link HttpSecurity} for further customizations
3911
- * @deprecated use {@link #securityMatcher(String)} instead
3930
+ * @deprecated use {@link #securityMatcher(String... )} instead
3912
3931
* @see AntPathRequestMatcher
3913
3932
*/
3914
3933
@ Deprecated
@@ -3929,7 +3948,7 @@ public HttpSecurity antMatcher(String antPattern) {
3929
3948
* </p>
3930
3949
* @param mvcPattern the Spring MVC Pattern to match on (i.e. "/admin/**")
3931
3950
* @return the {@link HttpSecurity} for further customizations
3932
- * @deprecated use {@link #securityMatcher(String)} instead
3951
+ * @deprecated use {@link #securityMatcher(String... )} instead
3933
3952
* @see MvcRequestMatcher
3934
3953
*/
3935
3954
@ Deprecated
0 commit comments