Skip to content

Fix : Wrap IllegalStateException as BadJwtException in NimbusJwtDecoder#19032

Open
chanani wants to merge 2 commits intospring-projects:mainfrom
chanani:gh-18388
Open

Fix : Wrap IllegalStateException as BadJwtException in NimbusJwtDecoder#19032
chanani wants to merge 2 commits intospring-projects:mainfrom
chanani:gh-18388

Conversation

@chanani
Copy link
Copy Markdown
Contributor

@chanani chanani commented Apr 3, 2026

Problem

When using OAuth2 Resource Server with JWT authentication, if a client
sends a token with an issuer different from the configured issuer-uri,
NimbusJwtDecoder.createJwt() propagates an IllegalStateException
from JwtDecoderProviderConfigurationUtils.validateIssuer().

Since JwtAuthenticationProvider only catches JwtException,
the IllegalStateException escapes the authentication pipeline,
causing the configured AuthenticationEntryPoint to not be invoked.

Solution

Catch IllegalStateException in NimbusJwtDecoder.createJwt() and
wrap it as BadJwtException so that the exception is properly handled
by the authentication pipeline.

Tests

  • Add decodeWhenIllegalStateExceptionThenThrowsBadJwtException()
    in NimbusJwtDecoderTests

Fixes gh-18388

Previously, an invalid issuer caused IllegalStateException to propagate
instead of BadJwtException, preventing AuthenticationEntryPoint from
being invoked.

Closes spring-projectsgh-18388

Signed-off-by: CHANHAN <130114269+chanani@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 3, 2026
…erTests

Signed-off-by: CHANHAN <130114269+chanani@users.noreply.github.com>
@chanani
Copy link
Copy Markdown
Contributor Author

chanani commented Apr 3, 2026

Hi @rwinch, I'd like to work on this issue.

The fix catches IllegalStateException in NimbusJwtDecoder.createJwt()
and wraps it as BadJwtException so it is properly handled by the authentication pipeline.

Please review my PR. Thank you !

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

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expect AuthenticationException for invalid issuer instead of IllegalStateException

2 participants