Skip to content

OAuth2AuthorizationServerJwtAutoConfiguration uses @ConditionalOnClass incorrectly #45177

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wilkinsona opened this issue Apr 14, 2025 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

@Bean
@ConditionalOnClass(JwtDecoder.class)
@ConditionalOnMissingBean
JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
}

This may break if JwtDecoder is not on the classpath as OAuth2AuthorizationServerJwtAutoConfiguration will still be loaded but it will declare a method whose signature refers to a class that does not exist.

@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ConditionalOnMissingBean
JWKSource<SecurityContext> jwkSource() {
RSAKey rsaKey = getRsaKey();
JWKSet jwkSet = new JWKSet(rsaKey);
return new ImmutableJWKSet<>(jwkSet);
}

There's no check here for com.nimbusds.jose.jwk.source.JWKSource or com.nimbusds.jose.proc.SecurityContext being on the classpath and the class only checks for org.springframework.security.oauth2.server.authorization.OAuth2Authorization.

It could be that the presence of OAuth2Authorization implies that the other classes must be present, or it may be that we need to introduce some inner-classes.

@wilkinsona wilkinsona added the type: bug A general bug label Apr 14, 2025
@wilkinsona wilkinsona added this to the 3.3.x milestone Apr 14, 2025
@wilkinsona wilkinsona self-assigned this Apr 14, 2025
@wilkinsona
Copy link
Member Author

The existing tests seem to imply that the conditions for the JwtDecoder bean should be separate to those of the auto-configuration as a whole so an inner-class is needed for the jwtDecoder bean definition.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant