Spring Security 自动装配
Posted pascall
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于Spring Security 自动装配的主要内容,如果未能解决你的问题,请参考以下文章
Spring security 无法自动装配 UserDetailsService
Spring Security WebSecurityConfigurerAdapter:AuthenticationManagerBuilder - 覆盖配置方法或自动装配 globalUserDe