EnableMfaFiltersConfiguration.mfaBeanPostProcessor() should be static to avoid BeanPostProcessorChecker warning
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- java, spring-boot
调研方向
工厂方法 mfaBeanPostProcessor() 声明在包 org.springframework.security.config.annotation.authorization 下的 EnableMfaFiltersConfiguration 中。打开该类,检查它返回的嵌套类 EnableMfaFiltersPostProcessor,然后为该方法添加 static 修饰符。当该方法为静态方法、项目可以编译,并且现有的配置测试仍然通过,且启动日志中没有 BeanPostProcessorChecker 警告时,即完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When @EnableMultiFactorAuthentication is used, the following warning is logged on every application startup:
WARN o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.authorization.EnableMfaFiltersConfiguration' of type [org.springframework.security.config.annotation.authorization.EnableMfaFiltersConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). The currently created BeanPostProcessor [mfaBeanPostProcessor] is declared through a non-static factory method on that class; consider declaring it as static instead.
EnableMfaFiltersConfiguration declares its BeanPostProcessor through a non-static @Bean method:
@Bean
BeanPostProcessor mfaBeanPostProcessor() {
return new EnableMfaFiltersPostProcessor();
}
Because the factory method is non-static, the configuration class itself has to be instantiated early, while post-processors are still being registered. This triggers the warning. The same code is present on main, 7.1.x, and 7.0.x.
To Reproduce
- Create a Spring Boot application with Spring Security.
- Add
@EnableMultiFactorAuthentication(authorities = {FactorGrantedAuthority.PASSWORD_AUTHORITY, FactorGrantedAuthority.OTT_AUTHORITY})to a@Configurationclass. - Start the application and check the startup log.
Expected behavior
No BeanPostProcessorChecker warning is logged for Spring Security's own infrastructure configuration.
Suggested fix
Declare the factory method as static. EnableMfaFiltersPostProcessor is already a private static nested class and does not depend on the enclosing instance, so this should be a safe one-line change:
@Bean
static BeanPostProcessor mfaBeanPostProcessor() {
return new EnableMfaFiltersPostProcessor();
}
Similar warnings were fixed this way in the past (e.g. gh-14751, gh-9845).
Environment
- Spring Boot 4.2.0
- Spring Security 7.2.0
- Spring Framework 7.1.0
- Java 25
Workaround
Suppress the logger:
logging:
level:
"[org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker]": error
- 主要语言
- Java
- 星标
- 9.7k
- 派生
- 6.4k
- 平均合并
- 5 天 35 分钟
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
spring-projects/spring-security 的其他 Issue
-
OidcUserInfo builder shoud accept Instant for the updateAt method可能已有人在做 @KaranCodez 于 22 天前认领。 未关闭status: waiting-for-triage type: bug
难度 2/5 1-3 小时 新手友好度 72/100
spring-projects/spring-security#20013 ·
维护者通常 5 天内回复
-
status: waiting-for-triage
难度 2/5 1-3 小时 新手友好度 62/100
spring-projects/spring-security#19996 ·
维护者通常 5 天内回复
-
Allow the HTTP QUERY method in the default firewalls可能已有人在做 @Sudhakar7J 于 21 天前认领。 未关闭status: waiting-for-triage type: enhancement
难度 2/5 1-3 小时 新手友好度 74/100
spring-projects/spring-security#19995 · 1 个 reaction ·
维护者通常 5 天内回复
-
status: waiting-for-triage
难度 2/5 1-3 小时 新手友好度 78/100
spring-projects/spring-security#19984 ·
维护者通常 5 天内回复
-
Spring-security-7.1.xsd schema validates request-matcher incorrectly可能已有人在做 @suryakant-source 于 32 天前认领。 未关闭status: waiting-for-triage type: bug
难度 2/5 1-3 小时 新手友好度 66/100
spring-projects/spring-security#19981 · 1 条评论 ·
维护者通常 5 天内回复
查看 spring-projects/spring-security 的全部 Issue