EnableMfaFiltersConfiguration.mfaBeanPostProcessor() should be static to avoid BeanPostProcessorChecker warning

未关闭 适合新手
#20,172 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 5 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, spring-boot

调研方向

工厂方法 mfaBeanPostProcessor() 声明在包 org.springframework.security.config.annotation.authorization 下的 EnableMfaFiltersConfiguration 中。打开该类,检查它返回的嵌套类 EnableMfaFiltersPostProcessor,然后为该方法添加 static 修饰符。当该方法为静态方法、项目可以编译,并且现有的配置测试仍然通过,且启动日志中没有 BeanPostProcessorChecker 警告时,即完成。

由索引模型根据 Issue 内容生成。

描述

status: waiting-for-triage type: bug

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

  1. Create a Spring Boot application with Spring Security.
  2. Add @EnableMultiFactorAuthentication(authorities = {FactorGrantedAuthority.PASSWORD_AUTHORITY, FactorGrantedAuthority.OTT_AUTHORITY}) to a @Configuration class.
  3. 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

spring-projects/spring-security 的其他 Issue

查看 spring-projects/spring-security 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。