我有一个 Spring Boot 应用程序,并且编写了一个自定义身份验证提供程序来验证我的 OAuth 令牌,但默认情况下 Spring Boot 支持 JWT,它会尝试检查我的 Oauth 令牌是否有声明等,这显然会返回错误。我怎样才能阻止它解码 JWT?
错误 97664 --- [nio-8080-exec-6] c.c.c.s.s.s.c.c.JwtConsumerDecoder:JWT 处理失败。其他详细信息:[[17] 无法处理 JOSE 对象(原因:org.jose4j.lang.JoseException:无效的 JOSE 紧凑序列化。分别期望 JWS 或 JWE 为 3 或 5 个部分,但实际为 1。):
@Configuration
public class SecurityConfig {
@Bean
public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception {
AuthenticationManagerBuilder authenticationManagerBuilder =
http.getSharedObject(AuthenticationManagerBuilder.class);
authenticationManagerBuilder.authenticationProvider(TokenAuthenticationProvider);
return authenticationManagerBuilder.build();
}
@Bean
public GrpcAuthenticationReader authenticationReader() {
BearerAuthenticationReader bearerAuthenticationReader = new BearerAuthenticationReader(BearerTokenAuthenticationToken::new);
return new CompositeGrpcAuthenticationReader(List.of(bearerAuthenticationReader));
}
@Bean
public GrpcSecurityMetadataSource grpcSecurityMetadataSource() {
return new ManualGrpcSecurityMetadataSource()
.setDefault(AccessPredicate.authenticated());
}
@Bean
public AccessDecisionManager accessDecisionManager() {
AccessPredicateVoter voter = new AccessPredicateVoter();
return new UnanimousBased(List.of(voter));
}
我使用的自定义提供程序没有导致问题的过滤器。