17
17
package org .springframework .security .config .annotation .web .builders ;
18
18
19
19
import java .util .ArrayList ;
20
+ import java .util .Arrays ;
20
21
import java .util .List ;
21
22
22
23
import javax .servlet .Filter ;
30
31
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
31
32
import org .springframework .context .ApplicationContext ;
32
33
import org .springframework .context .ApplicationContextAware ;
34
+ import org .springframework .core .log .LogMessage ;
33
35
import org .springframework .http .HttpMethod ;
34
36
import org .springframework .security .access .PermissionEvaluator ;
35
37
import org .springframework .security .access .expression .SecurityExpressionHandler ;
60
62
import org .springframework .security .web .firewall .HttpFirewall ;
61
63
import org .springframework .security .web .firewall .RequestRejectedHandler ;
62
64
import org .springframework .security .web .firewall .StrictHttpFirewall ;
65
+ import org .springframework .security .web .server .restriction .IgnoreRequestMatcher ;
63
66
import org .springframework .security .web .servlet .util .matcher .MvcRequestMatcher ;
64
67
import org .springframework .security .web .util .matcher .RequestMatcher ;
65
68
import org .springframework .security .web .util .matcher .RequestMatcherEntry ;
@@ -108,7 +111,7 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
108
111
109
112
private WebInvocationPrivilegeEvaluator privilegeEvaluator ;
110
113
111
- private DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler ();
114
+ private final DefaultWebSecurityExpressionHandler defaultWebSecurityExpressionHandler = new DefaultWebSecurityExpressionHandler ();
112
115
113
116
private SecurityExpressionHandler <FilterInvocation > expressionHandler = this .defaultWebSecurityExpressionHandler ;
114
117
@@ -420,6 +423,8 @@ public class IgnoredRequestConfigurer extends AbstractRequestMatcherRegistry<Ign
420
423
@ Override
421
424
public MvcMatchersIgnoredRequestConfigurer mvcMatchers (HttpMethod method , String ... mvcPatterns ) {
422
425
List <MvcRequestMatcher > mvcMatchers = createMvcMatchers (method , mvcPatterns );
426
+ Arrays .asList (mvcPatterns ).stream ().forEach ((t ) -> printWarnSecurityMessage (method , t ));
427
+ mvcMatchers .stream ().forEach ((t ) -> t .ignore ());
423
428
WebSecurity .this .ignoredRequests .addAll (mvcMatchers );
424
429
return new MvcMatchersIgnoredRequestConfigurer (getApplicationContext (), mvcMatchers );
425
430
}
@@ -429,6 +434,38 @@ public MvcMatchersIgnoredRequestConfigurer mvcMatchers(String... mvcPatterns) {
429
434
return mvcMatchers (null , mvcPatterns );
430
435
}
431
436
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
+
432
469
@ Override
433
470
protected IgnoredRequestConfigurer chainRequestMatchers (List <RequestMatcher > requestMatchers ) {
434
471
WebSecurity .this .ignoredRequests .addAll (requestMatchers );
@@ -442,6 +479,33 @@ public WebSecurity and() {
442
479
return WebSecurity .this ;
443
480
}
444
481
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
+
445
509
}
446
510
447
511
}
0 commit comments