8000 Log error event for TokenInterceptorException in token endpoint by wakqasahmed · Pull Request #52705 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Log error event for TokenInterceptorException in token endpoint - #52705

Merged
mposolda merged 1 commit into
keycloak:mainfrom
wakqasahmed:fix/token-interceptor-exception-event-logging
Sep 14, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
wakqasahmed:fix/token-interceptor-exception-event-logging

Conversation

@wakqasahmed
Copy link
Copy Markdown
Contributor

Closes #52568

TokenEndpoint's process() catches both TokenInterceptorException and RefreshTokenException around grant.process(context), but only the RefreshTokenException branch records an event detail/error before throwing. The TokenInterceptorException branch (hit whenever ResourceIndicatorsPostProcessor rejects an invalid, mismatched, or unresolvable resource indicator) throws straight away with no event logged, so these requests leave no trace in the admin/audit event log at all, unlike every other rejection path in this method.

This PR mirrors the existing RefreshTokenException handling: it records the exception's description as the event reason and logs Errors.INVALID_REQUEST before throwing the CorsErrorResponseException, matching the file's own established pattern for this kind of rejected-token-request error.

Added an integration test, testClientCredentialsInvalidResourceLogsErrorEvent in ResourceIndicatorsTest, that sends a client-credentials request with an invalid resource indicator and asserts the resulting error event is now recorded with the right error code and reason detail. Confirmed it fails on main (no event recorded) and passes with this fix.

AI disclosure: I used an AI coding assistant to help implement this fix and write the test, then reviewed and verified the change myself, including running the new test against a local build.

Testing

  • mvn -pl services -am compile — clean
  • mvn -pl tests/base -am install -DskipTests then -Dtest=ResourceIndicatorsTest#testClientCredentialsInvalidResourceLogsErrorEvent test — 1 test run, 0 failures

8000
Copilot AI balanced review requested due to automatic review settings September 12, 2026 06:06
@wakqasahmed
wakqasahmed requested a review from a team as a code owner September 12, 2026 06:06
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation follows existing error-event handling and includes appropriate integration coverage.

Pull request overview

Logs audit events when token post-processors reject token requests.

Changes:

  • Records the rejection reason and invalid_request event.
  • Adds integration coverage for invalid resource indicators.
File summaries
File Description
services/.../TokenEndpoint.java Logs TokenInterceptorException failures.
tests/.../ResourceIndicatorsTest.java Verifies the resulting client-login error event.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The TokenInterceptorException catch block in TokenEndpoint did not
record an event detail or error before throwing, unlike the sibling
RefreshTokenException catch block right below it. This meant every
rejected resource-indicator request (handled by
ResourceIndicatorsPostProcessor) left no admin/audit event trail at
all.

Mirror the RefreshTokenException catch block: record the exception's
description as the event reason and log Errors.INVALID_REQUEST before
throwing the CorsErrorResponseException, matching this method's
existing error-event convention.

Added an integration test (testClientCredentialsInvalidResourceLogsErrorEvent
in ResourceIndicatorsTest) asserting the event is now recorded, and
confirmed it fails without the fix and passes with it.

Closes keycloak#52568

Signed-off-by: wakqasahmed <training@saerintech.com>
@wakqasahmed
wakqasahmed force-pushed the fix/token-interceptor-exception-event-logging branch from 6af10a8 to 2bb23bd Compare September 13, 2026 07:31
@mposolda mposolda self-assigned this Sep 14, 2026
@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wakqasahmed Thanks!

@mposolda
mposolda merged commit 415d0a7 into keycloak:main Sep 14, 2026
93 of 94 checks passed
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.

ResourceIndicatorsPostProcessor error does not log appropriate error event

3 participants

0