我在升级到spring security core 6. 1时遇到了麻烦,我的过滤器链缺少jwt的解码器。问题是jwt.decoder()函数接受的唯一类JwtDecoder不再是受支持的类。
现在,我将其更改为如下所示:
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable).authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.oauth2ResourceServer(oauth->oauth.jwt(jwt->jwt.decoder()));
return http.build();
}
字符串
在从spring security oauth2切换到spring security 6之前,它看起来像下面的块
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests().anyRequest().permitAll();
}
型
我不相信我应该需要资源服务器在所有,但没有它,我收到一个“principalName不能为空错误”
需要帮助让新的像旧的那样工作。我愿意接受所有的请求。
2条答案
按热度按时间5anewei61#
JwtDecoder
仍然受支持,您可以在这里找到它:https://mvnrepository.com/artifact/org.springframework.security/spring-security-oauth2-jose如果你正在使用Maven,你可以将它添加到你的项目中:
字符串
对于Gradle:
型
h79rfbju2#
这在基本情况下应该足够了
字符串
更多细节,从这里开始。