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 javax .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
@@ -294,6 +291,8 @@ protected Filter performBuild() throws Exception {
294
291
List <SecurityFilterChain > securityFilterChains = new ArrayList <>(chainSize );
295
292
List <RequestMatcherEntry <List <WebInvocationPrivilegeEvaluator >>> requestMatcherPrivilegeEvaluatorsEntries = new ArrayList <>();
296
293
for (RequestMatcher ignoredRequest : this .ignoredRequests ) {
294
+ WebSecurity .this .logger .warn ("You are asking Spring Security to ignore " + ignoredRequest
295
+ + ". This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead." );
297
296
SecurityFilterChain securityFilterChain = new DefaultSecurityFilterChain (ignoredRequest );
298
297
securityFilterChains .add (securityFilterChain );
299
298
requestMatcherPrivilegeEvaluatorsEntries
@@ -423,8 +422,6 @@ public class IgnoredRequestConfigurer extends AbstractRequestMatcherRegistry<Ign
423
422
@ Override
424
423
public MvcMatchersIgnoredRequestConfigurer mvcMatchers (HttpMethod method , String ... mvcPatterns ) {
425
424
List <MvcRequestMatcher > mvcMatchers = createMvcMatchers (method , mvcPatterns );
426
- Arrays .asList (mvcPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (method , t ));
427
- mvcMatchers .stream ().forEach ((t ) -> t .ignore ());
428
425
WebSecurity .this .ignoredRequests .addAll (mvcMatchers );
429
426
return new MvcMatchersIgnoredRequestConfigurer (getApplicationContext (), mvcMatchers );
430
427
}
@@ -434,38 +431,6 @@ public MvcMatchersIgnoredRequestConfigurer mvcMatchers(String... mvcPatterns) {
434
431
return mvcMatchers (null , mvcPatterns );
435
432
}
436
433
437
- /**
438
- * @since 5.5
439
- */
440
- @ Override
441
- public IgnoredRequestConfigurer antMatchers (HttpMethod method ) {
442
- return antMatchers (method , "/**" );
443
- }
444
-
445
- /**
446
- * @since 5.5
447
- */
448
- @ Override
449
- public IgnoredRequestConfigurer antMatchers (HttpMethod method , String ... antPatterns ) {
450
- Assert .state (!this .anyRequestConfigured , "Can't configure antMatchers after anyRequest" );
451
- List <RequestMatcher > antMatchers = RequestMatchers .antMatchers (method , antPatterns );
452
- Arrays .asList (antPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (method , t ));
453
- antMatchers .stream ().forEach ((t ) -> ((IgnoreRequestMatcher ) t ).ignore ());
454
- return chainRequestMatchers (antMatchers );
455
- }
456
-
457
- /**
458
- * @since 5.5
459
- */
460
- @ Override
461
- public IgnoredRequestConfigurer antMatchers (String ... antPatterns ) {
462
- Assert .state (!this .anyRequestConfigured , "Can't configure antMatchers after anyRequest" );
463
- List <RequestMatcher > antMatchers = RequestMatchers .antMatchers (antPatterns );
464
- Arrays .asList (antPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (null , t ));
465
- antMatchers .stream ().forEach ((t ) -> ((IgnoreRequestMatcher ) t ).ignore ());
466
- return chainRequestMatchers (RequestMatchers .antMatchers (antPatterns ));
467
- }
468
-
469
434
@ Override
470
435
protected IgnoredRequestConfigurer chainRequestMatchers (List <RequestMatcher > requestMatchers ) {
471
436
WebSecurity .this .ignoredRequests .addAll (requestMatchers );
@@ -479,33 +444,6 @@ public WebSecurity and() {
479
444
return WebSecurity .this ;
480
445
}
481
446
482
- /**
483
- * @param method the HttpMethod, it could be null too.
484
- * @param pathPattern the path pattern to be ignored
485
- * @since 5.5
486
- */
487
- private void printWarnSecurityMessage (HttpMethod method , String pathPattern ) {
488
- if (pathPattern .equals ("/**" )) {
489
- WebSecurity .this .logger
490
- .warn ("**********************************************************************************" );
491
- if (method != null ) {
492
- WebSecurity .this .logger .warn (LogMessage .format (
493
- "Applying explicit instruction to ignore the '/**' path for the HttpMethod: %s" , method ));
494
- WebSecurity .this .logger .warn ("You're disabling practically all the paths for that HttpMethod" );
495
- WebSecurity .this .logger
496
- .warn ("Therefore any path for that HttpMethod is completely ignored by Spring Security" );
497
- }
498
- else {
499
- WebSecurity .this .logger .warn ("Applying explicit instruction to ignore the '/**' path" );
500
- WebSecurity .this .logger .warn ("You're disabling practically all the paths" );
501
- WebSecurity .this .logger .warn ("Therefore any path is completely ignored by Spring Security" );
502
- }
503
- WebSecurity .this .logger .warn ("It is not recomended for production" );
504
- WebSecurity .this .logger
505
- .warn ("**********************************************************************************" );
506
- }
507
- }
508
-
509
447
}
510
448
511
449
}
0 commit comments