Global AuthenticationManager spring security

Viewed 33

These days I have made the switch from WebSecurityConfigurerAdapter toSecurityFilterChain. In the class that initially extended the WebSecurityConfigurerAdapter I had this bean

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

now become:

 @Bean
 public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
         return authenticationConfiguration.getAuthenticationManager();
    }

it's correct? The application works correctly. The only problem is the tests using MockMvc which go into StackOverflowError due to this error:

Method threw 'org.springframework.beans.factory.BeanCurrentlyInCreationException' exception. Cannot evaluate com.sun.proxy.$Proxy103.toString()

I'm sure the problem is that bean, in fact if I try to remove it the tests work. In debugging I noticed that AuthenticationManagerBuilder which is used insideauthenticationConfiguration.getAuthenticationManager()in the case of tests is always null, so it goes to call this other method this.getAuthenticationManagerBean();

0 Answers
Related