gpt4 book ai didi

spring - 为什么 AuthenticationManager 会抛出 StackOverflowError?

转载 作者:行者123 更新时间:2023-12-05 08:39:52 24 4
gpt4 key购买 nike

我在调用 authenticationManger.authenticate() 时收到 StackOverflowError

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]

我正在尝试在我的应用程序中实现 JWT。我已经创建了 JWTTOkenUtil、过滤器和 Controller 。但只有身份验证管理器不工作。我也尝试过 CustomAuthenticationManger 但同样的错误。

文件 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

authenticationManager()authenticationManagerBean() 是两种不同的方法,您正在调用父类(super class)的 authenticationManagerBean() 方法,据我所知,这取决于 authenticationManager() 方法。这反过来会创建方法的循环调用,最终导致 StackOverflowError 异常。

您可以尝试不覆盖 AuthenticationManager authenticationManager() 方法,或者在这样做时返回可靠的实现。

关于spring - 为什么 AuthenticationManager 会抛出 StackOverflowError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58598448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com