前言:優先級高於ResourceServerConfigurer,用於保護oauth相關的endpoints,同時主要作用於用戶的登錄(form login,Basic auth)
WebSecurityConfigurerAdapter是默認情況下Spring security的http配置;ResourceServerConfigurerAdapter是默認情況下spring security oauth 的http配置。
下面貼出部分源碼:WebSecurityConfigurerAdapter類
@order(100)
public abstract class WebSecurityConfigurerAdapter implements WebSecurityConfigurer<WebSecurity> {
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
......
}
protected void configure(WebSecurity web) throws Exception {
......
}
protected void configure(HttpSecurity http) throws Exception {
........
}
}
ResourceServerConfigurerAdapter源碼:

在ResourceServerProperties中,定義了他的order默認值為SecurityProperties.ACCESS_OVERRIDE_ORDER -1;是大於100的,也就是WebSecurityConfigurerAdapter的配置攔截要優先於ResourceServerConfigurerAdapter,優先級高的http配置是可以覆蓋優先級低的配置的。
如果在一些特定的情況下需要ResourceServerConfigurerAdapter要高於WebSecurityConfigurerAdapter需要在配置文件中添加:
security.oauth2.resource.filter-order=99
或者是重寫WebSecurityConfigurerAdapter的order配置:
@Configuration
@EbableWebSecurity
@order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfigurerAdapter extends WebSecurityConfigurerAdapter{
.....
}
