最近在使用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