17
17
package org .springframework .security .config .annotation .web .builders ;
18
18
19
19
import java .util .ArrayList ;
20
- import java .util .Arrays ;
21
20
import java .util .List ;
22
21
23
22
import jakarta .servlet .Filter ;
31
30
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
32
31
import org .springframework .context .ApplicationContext ;
33
32
import org .springframework .context .ApplicationContextAware ;
34
- import org .springframework .core .log .LogMessage ;
35
33
import org .springframework .http .HttpMethod ;
36
34
import org .springframework .security .access .PermissionEvaluator ;
37
35
import org .springframework .security .access .expression .SecurityExpressionHandler ;
62
60
import org .springframework .security .web .firewall .HttpFirewall ;
63
61
import org .springframework .security .web .firewall .RequestRejectedHandler ;
64
62
import org .springframework .security .web .firewall .StrictHttpFirewall ;
65
- import org .springframework .security .web .server .restriction .IgnoreRequestMatcher ;
66
63
import org .springframework .security .web .servlet .util .matcher .MvcRequestMatcher ;
67
64
import org .springframework .security .web .util .matcher .RequestMatcher ;
68
65
import org .springframework .security .web .util .matcher .RequestMatcherEntry ;
@@ -111,7 +108,7 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
111
108
112
109
private WebInvocationPrivilegeEvaluator privilegeEvaluator ;
113
110
114
- private final DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler ();
111
+ private DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler ();
115
112
116
113
private SecurityExpressionHandler <FilterInvocation > expressionHandler = this .defaultWebSecurityExpressionHandler ;
117
114
@@ -307,6 +304,8 @@ protected Filter performBuild() throws Exception {
307
304
List <SecurityFilterChain > securityFilterChains = new ArrayList <>(chainSize );
308
305
List <RequestMatcherEntry <List <WebInvocationPrivilegeEvaluator >>> requestMatcherPrivilegeEvaluatorsEntries = new ArrayList <>();
309
306
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." );
310
309
SecurityFilterChain securityFilterChain = new DefaultSecurityFilterChain (ignoredRequest );
311
310
securityFilterChains .add (securityFilterChain );
312
311
requestMatcherPrivilegeEvaluatorsEntries
@@ -436,8 +435,6 @@ public class IgnoredRequestConfigurer extends AbstractRequestMatcherRegistry<Ign
436
435
@ Override
437
436
public MvcMatchersIgnoredRequestConfigurer mvcMatchers (HttpMethod method , String ... mvcPatterns ) {
438
437
List <MvcRequestMatcher > mvcMatchers = createMvcMatchers (method , mvcPatterns );
439
- Arrays .asList (mvcPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (method , t ));
440
- mvcMatchers .stream ().forEach ((t ) -> t .ignore ());
441
438
WebSecurity .this .ignoredRequests .addAll (mvcMatchers );
442
439
return new MvcMatchersIgnoredRequestConfigurer (getApplicationContext (), mvcMatchers );
443
440
}
@@ -447,38 +444,6 @@ public MvcMatchersIgnoredRequestConfigurer mvcMatchers(String... mvcPatterns) {
447
444
return mvcMatchers (null , mvcPatterns );
448
445
}
449
446
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
-
482
447
@ Override
483
448
protected IgnoredRequestConfigurer chainRequestMatchers (List <RequestMatcher > requestMatchers ) {
484
449
WebSecurity .this .ignoredRequests .addAll (requestMatchers );
@@ -492,33 +457,6 @@ public WebSecurity and() {
492
457
return WebSecurity .this ;
493
458
}
494
459
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
-
522
460
}
523
461
524
462
}
0 commit comments