1717package org .springframework .security .config .annotation .web .builders ;
1818
1919import java .util .ArrayList ;
20- import java .util .Arrays ;
2120import java .util .List ;
2221
2322import javax .servlet .Filter ;
3130import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
3231import org .springframework .context .ApplicationContext ;
3332import org .springframework .context .ApplicationContextAware ;
34- import org .springframework .core .log .LogMessage ;
3533import org .springframework .http .HttpMethod ;
3634import org .springframework .security .access .PermissionEvaluator ;
3735import org .springframework .security .access .expression .SecurityExpressionHandler ;
6260import org .springframework .security .web .firewall .HttpFirewall ;
6361import org .springframework .security .web .firewall .RequestRejectedHandler ;
6462import org .springframework .security .web .firewall .StrictHttpFirewall ;
65- import org .springframework .security .web .server .restriction .IgnoreRequestMatcher ;
6663import org .springframework .security .web .servlet .util .matcher .MvcRequestMatcher ;
6764import org .springframework .security .web .util .matcher .RequestMatcher ;
6865import org .springframework .security .web .util .matcher .RequestMatcherEntry ;
@@ -111,7 +108,7 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
111108
112109 private WebInvocationPrivilegeEvaluator privilegeEvaluator ;
113110
114- private final DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler ();
111+ private DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler ();
115112
116113 private SecurityExpressionHandler <FilterInvocation > expressionHandler = this .defaultWebSecurityExpressionHandler ;
117114
@@ -307,6 +304,8 @@ protected Filter performBuild() throws Exception {
307304 List <SecurityFilterChain > securityFilterChains = new ArrayList <>(chainSize );
308305 List <RequestMatcherEntry <List <WebInvocationPrivilegeEvaluator >>> requestMatcherPrivilegeEvaluatorsEntries = new ArrayList <>();
309306 for (RequestMatcher ignoredRequest : this .ignoredRequests ) {
307+ WebSecurity .this .logger .warn ("You are asking Spring Security to ignore " + ignoredRequest
308+ + ". This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead." );
310309 SecurityFilterChain securityFilterChain = new DefaultSecurityFilterChain (ignoredRequest );
311310 securityFilterChains .add (securityFilterChain );
312311 requestMatcherPrivilegeEvaluatorsEntries
@@ -436,8 +435,6 @@ public class IgnoredRequestConfigurer extends AbstractRequestMatcherRegistry<Ign
436435 @ Override
437436 public MvcMatchersIgnoredRequestConfigurer mvcMatchers (HttpMethod method , String ... mvcPatterns ) {
438437 List <MvcRequestMatcher > mvcMatchers = createMvcMatchers (method , mvcPatterns );
439- Arrays .asList (mvcPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (method , t ));
440- mvcMatchers .stream ().forEach ((t ) -> t .ignore ());
441438 WebSecurity .this .ignoredRequests .addAll (mvcMatchers );
442439 return new MvcMatchersIgnoredRequestConfigurer (getApplicationContext (), mvcMatchers );
443440 }
@@ -447,38 +444,6 @@ public MvcMatchersIgnoredRequestConfigurer mvcMatchers(String... mvcPatterns) {
447444 return mvcMatchers (null , mvcPatterns );
448445 }
449446
450- /**
451- * @since 5.5
452- */
453- @ Override
454- public IgnoredRequestConfigurer antMatchers (HttpMethod method ) {
455- return antMatchers (method , "/**" );
456- }
457-
458- /**
459- * @since 5.5
460- */
461- @ Override
462- public IgnoredRequestConfigurer antMatchers (HttpMethod method , String ... antPatterns ) {
463- Assert .state (!this .anyRequestConfigured , "Can't configure antMatchers after anyRequest" );
464- List <RequestMatcher > antMatchers = RequestMatchers .antMatchers (method , antPatterns );
465- Arrays .asList (antPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (method , t ));
466- antMatchers .stream ().forEach ((t ) -> ((IgnoreRequestMatcher ) t ).ignore ());
467- return chainRequestMatchers (antMatchers );
468- }
469-
470- /**
471- * @since 5.5
472- */
473- @ Override
474- public IgnoredRequestConfigurer antMatchers (String ... antPatterns ) {
475- Assert .state (!this .anyRequestConfigured , "Can't configure antMatchers after anyRequest" );
476- List <RequestMatcher > antMatchers = RequestMatchers .antMatchers (antPatterns );
477- Arrays .asList (antPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (null , t ));
478- antMatchers .stream ().forEach ((t ) -> ((IgnoreRequestMatcher ) t ).ignore ());
479- return chainRequestMatchers (RequestMatchers .antMatchers (antPatterns ));
480- }
481-
482447 @ Override
483448 protected IgnoredRequestConfigurer chainRequestMatchers (List <RequestMatcher > requestMatchers ) {
484449 WebSecurity .this .ignoredRequests .addAll (requestMatchers );
@@ -492,33 +457,6 @@ public WebSecurity and() {
492457 return WebSecurity .this ;
493458 }
494459
495- /**
496- * @param method the HttpMethod, it could be null too.
497- * @param pathPattern the path pattern to be ignored
498- * @since 5.5
499- */
500- private void printWarnSecurityMessage (HttpMethod method , String pathPattern ) {
501- if (pathPattern .equals ("/**" )) {
502- WebSecurity .this .logger
503- .warn ("**********************************************************************************" );
504- if (method != null ) {
505- WebSecurity .this .logger .warn (LogMessage .format (
506- "Applying explicit instruction to ignore the '/**' path for the HttpMethod: %s" , method ));
507- WebSecurity .this .logger .warn ("You're disabling practically all the paths for that HttpMethod" );
508- WebSecurity .this .logger
509- .warn ("Therefore any path for that HttpMethod is completely ignored by Spring Security" );
510- }
511- else {
512- WebSecurity .this .logger .warn ("Applying explicit instruction to ignore the '/**' path" );
513- WebSecurity .this .logger .warn ("You're disabling practically all the paths" );
514- WebSecurity .this .logger .warn ("Therefore any path is completely ignored by Spring Security" );
515- }
516- WebSecurity .this .logger .warn ("It is not recomended for production" );
517- WebSecurity .this .logger
518- .warn ("**********************************************************************************" );
519- }
520- }
521-
522460 }
523461
524462}
0 commit comments