前言:优先级高于ResourceServerConfigurer,用于保护oauth相关的endpoints,同时主要做用于用户的登陆(form login,Basic auth)java
WebSecurityConfigurerAdapter是默认状况下Spring security的http配置;ResourceServerConfigurerAdapter是默认状况下spring security oauth 的http配置。web
下面贴出部分源码:WebSecurityConfigurerAdapter类spring
@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源码:ui
在ResourceServerProperties中,定义了他的order默认值为SecurityProperties.ACCESS_OVERRIDE_ORDER -1;是大于100的,也就是WebSecurityConfigurerAdapter的配置拦截要优先于ResourceServerConfigurerAdapter,优先级高的http配置是能够覆盖优先级低的配置的。3d
若是在一些特定的状况下须要ResourceServerConfigurerAdapter要高于WebSecurityConfigurerAdapter须要在配置文件中添加:code
security.oauth2.resource.filter-order=99
或者是重写WebSecurityConfigurerAdapter的order配置:orm
@Configuration @EbableWebSecurity @order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class SecurityConfigurerAdapter extends WebSecurityConfigurerAdapter{ ..... }