最近在使用spring security作登录鉴权。登录界面相关CSS和JS,以及部分api接口须要忽略,因而代码中用到了anyMatchers。以下所示:css
1 @Override 2 public void configure(WebSecurity web) throws Exception { 3 // AuthenticationTokenFilter will ignore the below paths 4 web 5 .ignoring() 6 .antMatchers( 7 HttpMethod.POST, 8 authenticationPath 9 ) 10 11 // allow anonymous resource requests 12 .and() 13 .ignoring() 14 .antMatchers( 15 HttpMethod.GET, 16 "/", 17 "/*.html", 18 "/favicon.ico", 19 "/**/*.html", 20 "/**/*.css", 21 "/**/*.js" 22 ) 23 24 // Un-secure H2 Database (for testing purposes, H2 console shouldn't be unprotected in production) 25 .and() 26 .ignoring() 27 .antMatchers("/h2-console/**/**"); 28 }
相似于正则的**或者*都表示什么含义呢?查询了相关文档,简单的作一下总结,方便往后查询。html
[a-z]+
as a path variable named "spring")例子:java
参考: web
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html 正则表达式
https://www.w3schools.com/jsref/jsref_regexp_wordchar.asp spring