Skip to content

ReactiveMethodSecurityConfiguration is initialized prematurely when the context contains a BeanPostProcessor #11596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wilkinsona opened this issue Jul 19, 2022 · 7 comments
Assignees
Labels
in: config An issue in spring-security-config type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Jul 19, 2022

Describe the bug
ReactiveMethodSecurityConfiguration is initialized prematurely when the context contains a BeanPostProcessor. This results in the following log message:

11:04:02.687 [main] INFO org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.method.configuration.ReactiveMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.ReactiveMethodSecurityConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

To Reproduce

package com.example.demo;

import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.web.reactive.config.EnableWebFlux;

@Configuration
@ComponentScan
@EnableWebFlux
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class DemoApplication {

	public static void main(String[] args) {
		new AnnotationConfigApplicationContext(DemoApplication.class);
	}

	@Bean
	static BeanPostProcessor exampleBeanPostProcessor() {
		return new BeanPostProcessor() {

		};
	}

	@Bean
	SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
		return http.build();
	}

}

Expected behavior

All beans are eligible for post-processing.

Sample

There's a sample Spring Boot application attached to this Spring Boot issue. The code above is a reduced version of that sample that takes Boot out of the picture.

@sjohnr
Copy link
Contributor

sjohnr commented Jul 19, 2022

Thanks @wilkinsona. Is there a sense around the urgency of this issue? I'm not sure I understand the impact very well.

@wilkinsona
Copy link
Member Author

wilkinsona commented Jul 19, 2022

As far as I can tell, the problem's benign from a Spring Security perspective as ReactiveMethodSecurityConfiguration doesn't typically need to be post-processed. However, as you can tell from the Boot issue, the log message is causing confusion for users and is really a usability bug.

I have quite a bit of sympathy for users dealing with the message. It's indicating that something's wrong and potentially won't work as intended so it's right that they should care about it, understand it, and ideally stop it from happening. Given that it's our code that's causing the problem, I think it should be fixed so that we avoid wasting their time diagnosing it, particularly as there's nothing they can do to fix it. They can't even tune their logging levels as they may then miss other messages for a similar problem which isn't benign.

@sjohnr
Copy link
Contributor

sjohnr commented Jul 19, 2022

Thanks @wilkinsona!

@sjohnr sjohnr added in: config An issue in spring-security-config and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 19, 2022
@sjohnr sjohnr added this to the 6.0.x milestone Jul 19, 2022
@jzheaux
Copy link
Contributor

jzheaux commented Jul 20, 2022

Related to #9845 - (summary: it may be appropriate to add @Role(BeanDefinition.ROLE_INFRASTRUCTURE))

@wilkinsona
Copy link
Member Author

I notice that this has been assigned to the 6.0.x milestone. Could you please consider fixing it in all 5.x maintenance branches?

@sjohnr
Copy link
Contributor

sjohnr commented Jul 22, 2022

Good question @wilkinsona. As a team, we have generally assigned bugs to the latest branch where the bug applies and then backport bugs to maintenance branches. It's gotten a little confusing with 5.8 and 6.0 being developed simultaneously. Unfortunately, I can't assign an issue to multiple milestones otherwise I would do so. But we will definitely backport a fix if at all possible.

@jzheaux jzheaux modified the milestones: 6.0.x, 5.7.7 Jan 11, 2023
@jzheaux jzheaux self-assigned this Jan 11, 2023
@sjohnr sjohnr modified the milestones: 5.7.7, 5.7.8 Feb 21, 2023
@marcusdacoregio marcusdacoregio modified the milestones: 5.7.8, 5.7.9 Apr 17, 2023
@marcusdacoregio marcusdacoregio modified the milestones: 5.7.9, 5.8.5 Jun 17, 2023
@marcusdacoregio marcusdacoregio modified the milestones: 5.8.5, 5.8.6 Jul 17, 2023
@sjohnr sjohnr modified the milestones: 5.8.6, 5.8.7 Aug 19, 2023
@sjohnr sjohnr modified the milestones: 5.8.7, 5.8.8 Sep 18, 2023
@sjohnr sjohnr modified the milestones: 5.8.8, 5.8.9 Oct 13, 2023
@jzheaux
Copy link
Contributor

jzheaux commented Dec 18, 2023

Looking at this further, I think that the case is the bean methods should use static in their signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: config An issue in spring-security-config type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants