SecurityBuilder
public interface SecurityBuilder<O> {
O build() throws Exception;
}
这个Builder
的重要子类
-
AuthenticationManagerBuilder
要build的对象是AuthenticationManager
-
WebSecurity
要build的对象是Filter
-
HttpSecurity
要build的对象是DefaultSecurityFilterChain
SecurityConfigurer
public interface SecurityConfigurer<O, B extends SecurityBuilder<O>> {
//Initialize the {@link SecurityBuilder}.
void init(B builder) throws Exception;
//Configure the {@link SecurityBuilder} by setting the necessary properties on the
void configure(B builder) throws Exception;
}
这个SecurityConfigurer
重要子类就是WebSecurityConfigurerAdapter
spring security的配置主要是由WebSecurityConfiguration
实现的,WebSecurityConfigurerAdapter
或者其子类被添加到WebSecurity
的属性private final LinkedHashMap<Class<? extends SecurityConfigurer<O, B>>, List<SecurityConfigurer<O, B>>> configurers = new LinkedHashMap<>();
中,在WebSecurityConfigurerAdapter
配置WebSecurity
的过程中,init这一步会创建HttpSecurity
实例对象http,并调用WebSecurity
的addSecurityFilterChainBuilder
这一个方法,把http添加到WebSecurity
的securityFilterChainBuilders