Add @ConditionalOnWebApplication to ReactiveOAuth2ResourceServerAutoConfiguration#49812
Closed
daguimu wants to merge 1 commit intospring-projects:mainfrom
Closed
Add @ConditionalOnWebApplication to ReactiveOAuth2ResourceServerAutoConfiguration#49812daguimu wants to merge 1 commit intospring-projects:mainfrom
daguimu wants to merge 1 commit intospring-projects:mainfrom
Conversation
…onfiguration ReactiveOAuth2ResourceServerAutoConfiguration was only conditional on the presence of Mono and BearerTokenAuthenticationToken classes. When a Servlet-based application includes dependencies that pull in reactor-core (e.g., spring-boot-starter-data-redis via Lettuce), the auto-configuration was triggered incorrectly, causing a NoClassDefFoundError for WebClient at startup. Add @ConditionalOnWebApplication(type = Type.REACTIVE) to ensure the auto-configuration only activates for reactive web applications, consistent with ReactiveOAuth2ResourceServerWebSecurityAutoConfiguration. Fixes spring-projects#49807
Member
|
Thanks for the PR but this isn't the right fix as it would regress #43978. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a Servlet-based application includes dependencies that pull in
reactor-core(e.g.,spring-boot-starter-data-redisvia Lettuce),ReactiveOAuth2ResourceServerAutoConfigurationis triggered incorrectly, causing aNoClassDefFoundErrorforWebClientat startup.Root Cause
ReactiveOAuth2ResourceServerAutoConfigurationonly checks for the presence ofMono.classandBearerTokenAuthenticationToken.classvia@ConditionalOnClass. Since libraries like Lettuce bringreactor-core(and thusMono) onto the classpath for their own async internals, the condition is satisfied even in Servlet-based applications. The importedReactiveJwtDecoderConfigurationthen attempts to create aNimbusReactiveJwtDecoderwhich requiresWebClientfromspring-webflux, which is not present.Fix
@ConditionalOnWebApplication(type = Type.REACTIVE)toReactiveOAuth2ResourceServerAutoConfigurationto ensure it only activates for reactive web applicationsReactiveOAuth2ResourceServerWebSecurityAutoConfiguration, which already has this conditionTests Added
@ConditionalOnWebApplication(type = Type.REACTIVE)autoConfigurationShouldBeConditionalOnReactiveWebApplication()— verifies that noReactiveJwtDecoderorReactiveOpaqueTokenIntrospectorbeans are created when running in a Servlet web application contextImpact
Only affects the activation condition of the reactive OAuth2 resource server auto-configuration. Servlet-based applications will no longer incorrectly trigger this configuration. Reactive web applications are unaffected as the condition is satisfied in that context.
Fixes #49807