Skip to content

OAuth2 resource server ignores authorities-claim-delimiter when set on its own - #51619

Merged
wilkinsona merged 1 commit into
spring-projects:4.0.xfrom
yyuneu:fix/jwt-converter-authorities-claim-delimiter
Sep 8, 2026
Merged

wilkinsona merged 1 commit into
spring-projects:4.0.xfrom
yyuneu:fix/jwt-converter-authorities-claim-delimiter

Conversation

@yyuneu

@yyuneu yyuneu commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What happened?

Setting spring.security.oauth2.resourceserver.jwt.authorities-claim-delimiter without any other JWT converter properties has no effect. For example, given a JWT with a scope claim of read,write and the following configuration:

spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://example.com/.well-known/jwks.json
spring.security.oauth2.resourceserver.jwt.authorities-claim-delimiter=,

The resulting authentication has a single authority, SCOPE_read,write, instead of SCOPE_read and SCOPE_write. An authorization rule using hasAuthority('SCOPE_read') therefore denies access.

In both OAuth2ResourceServerJwtConfiguration and its reactive counterpart, JwtConverterConfiguration is guarded by JwtConverterPropertiesCondition. This AnyNestedCondition checks three properties:

  • authority-prefix
  • principal-claim-name
  • authorities-claim-name

The converter bean method also applies authorities-claim-delimiter, but that property is missing from the condition. When it is the only converter property set, the condition does not match and Spring Boot does not configure a converter bean. Spring Security then uses its default converter, which splits the claim on a single space.

Support for all four properties was added in #38105. The condition added as part of that change checks only three of them.

The existing "Custom delimiter for JWT scopes" test case did not catch this because it also set authority-prefix, which satisfied the condition.

What does this PR change?

Adds a nested condition for authorities-claim-delimiter to JwtConverterPropertiesCondition in both the servlet and reactive configurations. Setting the delimiter alone now enables the converter configuration.

Unset properties retain their defaults because PropertyMapper skips null values. User-defined converter beans still take precedence through @ConditionalOnMissingBean.

The delimiter is also missing from the corresponding conditions on 4.1.x and main, where they live in JwtConverterConfiguration.PropertiesCondition and ReactiveJwtConverterConfiguration.PropertiesCondition.

Tests

  • Added shouldConfigureJwtConverterIfAuthoritiesClaimDelimiterIsSet to both OAuth2ResourceServerAutoConfigurationTests and ReactiveOAuth2ResourceServerAutoConfigurationTests, following the existing tests for the other three properties.
  • Updated the "Custom delimiter for JWT scopes" case in JwtConverterCustomizationsArgumentsProvider to set the delimiter without a custom authority prefix. It now expects the split scopes to use the default SCOPE_ prefix.

The new tests and the updated parameterized case fail without the fix. The parameterized case fails with NoSuchBeanDefinitionException because no converter bean is configured.

:module:spring-boot-security-oauth2-resource-server:check passes with JDK 25.

yyuneu added a commit to yyuneu/spring-boot that referenced this pull request Sep 8, 2026
See spring-projectsgh-51619

Signed-off-by: JaeHyunAn <98042706+yyuneu@users.noreply.github.com>
@yyuneu
yyuneu force-pushed the fix/jwt-converter-authorities-claim-delimiter branch from bc55619 to a84919a Compare September 8, 2026 09:02
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Sep 8, 2026
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Sep 8, 2026
@wilkinsona wilkinsona added this to the 4.0.x milestone Sep 8, 2026
@wilkinsona wilkinsona self-assigned this Sep 8, 2026
See spring-projectsgh-51619

Signed-off-by: JaeHyunAn <98042706+yyuneu@users.noreply.github.com>
@wilkinsona
wilkinsona force-pushed the fix/jwt-converter-authorities-claim-delimiter branch from a84919a to 537c80d Compare September 8, 2026 15:40
@wilkinsona wilkinsona modified the milestones: 4.0.x, 4.0.9 Sep 8, 2026
@wilkinsona
wilkinsona merged commit bfc2935 into spring-projects:4.0.x Sep 8, 2026
3 of 4 checks passed
@wilkinsona

Copy link
Copy Markdown
Member

Thank you, @yyuneu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants