Skip to content

Conversation

Kehrlann
Copy link
Contributor

Spring Security relies on specific exceptions (based on ClientAuthorizationException) to signal that an OAuth2 token should be requested.

With the recent changes in Spring AI, those exceptions were now swallowed and sent to the LLM, or, with the appropriate property, rethrown after being wrapped in another exception. This broke OAuth2 flows. With this PR, we change the default behavior to rethrow spring security OAuth2 exceptions in the DefaultToolExecutionExceptionProcessor.

The DefaultToolExecutionExceptionProcessor now has an allowlist of exceptions that will be rethrown instead of being wrapped.

Kehrlann added 2 commits June 18, 2025 17:39
…onProcessor

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
@ilayaperumalg ilayaperumalg added this to the 1.1.x milestone Jun 19, 2025
tzolov pushed a commit that referenced this pull request Jun 20, 2025
…tionProcessor (#3595)

This allows certain exceptions (like OAuth2 authorization errors) to bubble up
properly instead of being wrapped, enabling correct authentication flows.

- Add support for configuring allowlist of exceptions to be rethrown directly
- Enhance DefaultToolExecutionExceptionProcessor with builder pattern
- Add automatic detection and handling of OAuth2 ClientAuthorizationException
- Update ToolCallingAutoConfiguration to configure OAuth2 exception rethrowing
- Add unit tests for new exception handling behavior

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
@tzolov
Copy link
Contributor

tzolov commented Jun 20, 2025

Thanks @Kehrlann
LGTM

tzolov pushed a commit that referenced this pull request Jun 20, 2025
…tionProcessor (#3595)

This allows certain exceptions (like OAuth2 authorization errors) to bubble up
properly instead of being wrapped, enabling correct authentication flows.

- Add support for configuring allowlist of exceptions to be rethrown directly
- Enhance DefaultToolExecutionExceptionProcessor with builder pattern
- Add automatic detection and handling of OAuth2 ClientAuthorizationException
- Update ToolCallingAutoConfiguration to configure OAuth2 exception rethrowing
- Add unit tests for new exception handling behavior

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
@tzolov
Copy link
Contributor

tzolov commented Jun 20, 2025

Rebased, squashed and merged at beb1d05
Back ported to 1.0.x

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

Successfully merging this pull request may close these issues.

3 participants