-
Notifications
You must be signed in to change notification settings - Fork 41.2k
SpringBootWebSecurityConfiguration missing @EnableWebSecurity #10236
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
Comments
|
I already tried importing I'm actually suggesting to add
This is the designed approach when enabling security - when extending Although
it does not kick in before the auto-wiring of My suspicion is that it's because Does |
@wilkinsona So I figured out that this is actually an ordering issue. Thanks to your comment that gave me this clue.
whereas
So there is an ordering issue going on here with the auto-config classes. I'm going to re-work things based on some of your comments in the PR. |
When I run the tests in
OAuth2ClientAutoConfigurationTests
, I get the following exception:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$DefaultConfigurerAdapter': Unsatisfied dependency expressed through method 'setObjectPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor<java.lang.Object>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
This exception is caused because
SpringBootWebSecurityConfiguration.DefaultConfigurerAdapter
is not annotated with@EnableWebSecurity
.SpringBootWebSecurityConfiguration.DefaultConfigurerAdapter
is annotated with@Configuration
and extendsWebSecurityConfigurerAdapter
. So the expectation would be thatWebSecurityEnablerConfiguration
will automatically import the required@Configuration
's because it's annotated with@EnableWebSecurity
for these specific cases.However,
WebSecurityEnablerConfiguration
does not kick in at all because when the context creates and then tries to auto-wireSpringBootWebSecurityConfiguration.DefaultConfigurerAdapter.setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor)
it can't find the required dependency in the context and so the exception is triggered.If you replace the
@Configuration
with@EnableWebSecurity
then the tests will pass. For example:When a class extends
WebSecurityConfigurerAdapter
, it should also be annotated with@EnableWebSecurity
to ensure the required@Configuration
's are imported.The text was updated successfully, but these errors were encountered: