Skip to content

@Bean of AuthenticationManager from WebSecurityConfigurerAdapter throws either StackOverflowError or OutOfMemoryError #10477

Closed
@matheusg-morillo

Description

@matheusg-morillo

Describe the bug
I'm overriding the authenticationManager method from the WebSecurityConfigurerAdapter in order to create its bean, howerver whenever I try to turn the spring context up (in a test annotated with a @SpringBootTest for example), I get either a StackOverflowError or OutOfMemoryError. I tracked this error to the authenticationManager method, because whenever I remove the @bean annotation the error disappears.

I'm using gradle, Java 11 and spring-boot-starter-security version 2.5.6

To Reproduce

  1. Override the authenticationManager from the WebSecurityConfigurerAdapter class and add a Bean annotation
  2. Try to run a test annotated with SpringBootTest
@EnableWebSecurity
@Configuration
public class SecurityConfigurations extends WebSecurityConfigurerAdapter {

    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }
    ...

Expected behavior
Being able to run the app and inject the authenticationManager bean

Sample
https://github.com/mmorillodev/stackoverflow-error-sample

Metadata

Metadata

Assignees

Labels

in: coreAn issue in spring-security-corestatus: duplicateA duplicate of another issuetype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions