Spring Security 自动装配

1、自动装配的配置类

org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration         // 自动装配类
  • 注册DefaultAuthenticationEventPublisher
org.springframework.boot.autoconfigure.security.SecurityProperties                  // properties对应的属性配置类
org.springframework.boot.autoconfigure.security.servlet.SpringBootWebSecurityConfiguration    // 注入配置类,用于装载Spring Security个性化配置(WebSecurityConfigurerAdapter: DefaultConfigurerAdapter
org.springframework.boot.autoconfigure.security.servlet.WebSecurityEnablerConfiguration       // 开启@EnableWebSecurity手动装配
@EnableWebSecurity
  WebSecurityConfiguration:
  • 实现ImportAware, BeanClassLoaderAware接口,加载debugEnabled(boolean),beanClassLoader(ClassLoader)属性
  • 注入objectObjectPostProcessor(ObjectPostProcessor<Object>)属性  (AutowiredBeanFactoryObjectPostProcessor
  • 注册AutowiredWebSecurityConfigurersIgnoreParents,用于获取WebSecurityConfigurer类型Bean,并转化为List<WebSecurityConfigurer<Filter, WebSecurity>>格式
  • 使用objectObjectPostProcessor(AutowiredBeanFactoryObjectPostProcessor)创建webSecurity(WebSecurity)属性
  • 使用AutowiredWebSecurityConfigurersIgnoreParents获取List<WebSecurityConfigurer<Filter, WebSecurity>>并赋值给webSecurityConfigurers属性
  • 将webSecurityConfigurers中的WebSecurity值全部添加到webSecurity属性中
  • 注册DelegatingApplicationListener
  • 注册springSecurityFilterChain(Filter),创建DefaultSecurityFilterChain,加载默认的15个过滤器,创建FilterChainProxy,代理过滤器链
  • 注册SecurityExpressionHandler<FilterInvocation>
  • 注册WebInvocationPrivilegeEvaluator(DefaultWebInvocationPrivilegeEvaluator)

  SpringWebMvcImportSelector:

  • 选择注册WebMvcSecurityConfiguration

  OAuth2ImportSelector:

  • 选择注册OAuth2ClientConfiguration

  @EnableGlobalAuthentication

    AuthenticationConfiguration

    • 导入ObjectPostProcessorConfiguration,注册AutowiredBeanFactoryObjectPostProcessor
    • 注册AuthenticationManagerBuilder,EnableGlobalAuthenticationAutowiredConfigurer,InitializeUserDetailsBeanManagerConfigurer,InitializeAuthenticationProviderBeanManagerConfigurer

 

posted @ 2019-06-15 11:48  张界  阅读(824)  评论(0编辑  收藏  举报