spring-projects / spring-projects/spring-boot

Application with a user-defined OpaqueTokenIntrospector fails to start when spring.security.oauth2.resourceserver.opaquetoken.introspection-uri is set

Open
#50,479 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: team-only type: regression
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

When trying out Spring Boot 4.1.0-RC1 in a WebMVC based application (previously on Spring Boot 4.0), I noticed a bunch of new beans are now being created by the config classes imported by ReactiveOAuth2ResourceServerAutoConfiguration.

In Spring Boot 4.0, ReactiveOAuth2ResourceServerAutoConfiguration was annotated with @ConditionalOnWebApplication(type = Type.REACTIVE), but in 4.1.0-RC1 it is not. I understand this was done to enable Spring Security related concepts in non-webapps (#43978).

However, for WebMVC apps that don't need the reactive beans, it's resulting in creation of a bunch of additional unwanted beans.

I probably wouldn't have noticed, except that creation of one of those reactive beans is failing in our apps (caused by this assertion). In our apps, we've overridden the OpaqueTokenIntrospector bean, so that the corresponding assertion for WebMVC does not fail (our introspection endpoint does not use basic auth, so we have to configure the introspector slightly differently).

To work around this... we could define a ReactiveOpaqueTokenIntrospector bean to prevent the problematic bean from being created. However, this feels "wrong", because we don't need/want reactive introspection support at all in our WebMVC apps.

Alternatively, we could exclude ReactiveOAuth2ResourceServerAutoConfiguration. But that also feels wrong. IMHO the reactive resource server related beans should be opt-in in a WebMVC based app, not opt-out. In other words, @ConditionalOnClass({ Mono.class, BearerTokenAuthenticationToken.class }) does not feel like a "strong enough" condition to enable this autoconfiguration in WebMVC based apps. Mono being on the classpath doesn't necessarily mean the app needs reactive introspection support, since Mono could just be used internally by some other dependency, and not a key component of the app.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ReactiveOAuth2ResourceServerAutoConfiguration and compare its conditions with OpaqueTokenIntrospectionConfiguration and ReactiveOpaqueTokenIntrospectionClientConfiguration, the files linked in the report. Reproduce a WebMVC application with the introspection URI and a user-defined OpaqueTokenIntrospector, then verify that unnecessary reactive resource-server beans no longer cause startup failure while reactive applications and non-web use cases remain supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.