I am getting StackOverflowError
while calling authenticationManger.authenticate()
java.lang.StackOverflowError: null at org.apache.commons.logging.LogAdapter$Slf4jLog.isDebugEnabled(LogAdapter.java:300) ~[spring-jcl-5.1.10.RELEASE.jar:5.1.10.RELEASE] at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:162) ~[spring-security-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$AuthenticationManagerDelegator.authenticate(WebSecurityConfigurerAdapter.java:503) ~[spring-security-config-5.1.6.RELEASE.jar:5.1.6.RELEASE]
I am trying to implement JWT in my application. I have created JWTTOkenUtil
, Filter, Controller. But only Authentication manager is not working. I have tried with CustomAuthenticationManger
as well but same error.
File AppConfig.java
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class AppConfig extends WebSecurityConfigurerAdapter{
@Autowired
private JwtUserDetailService jwtUserDetailService;
@Autowired
private JwtAuthenticationProvider jwtAuthenticationProvider;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(jwtAuthenticationProvider);
//auth.userDetailsService(jwtUserDetailService).passwordEncoder(passwordEncoder());
}
@Bean
@Override
public AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests().antMatchers("/version").permitAll()
.anyRequest().authenticated()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtRequestFilter(), UsernamePasswordAuthenticationFilter.class);
}
@Bean
public JwtRequestFilter jwtRequestFilter() {
return new JwtRequestFilter();
}
}
WebSecurityConfigurerAdapter.java:503
line numberdelegate.authenticate(authentication);
where delegate is declared asprivate AuthenticationManager delegate;
And you have not given complete logs, even not good formatted logs. But in logs i didn't see null pointer, but it showsjava.lang.StackOverflowError: null at
this much i can figure out. As you have not provided code ofJwtAuthenticationProvider
question seems to be have incomplete information. – FaradismAuthenticationManager authenticationManager()
method.authenticationManager()
andauthenticationManagerBean()
ofWebSecurityConfigurerAdapter
are two different methods, and you are callingauthenticationManagerBean()
method of yoursuper
class, which, as far as I know, depends onauthenticationManager()
method. This, in return creates a cyclic calls of methods. – Stella