Add a client-activity workflow event provider - #53082
Open
antoniocasagrande-airia wants to merge 2 commits into
Open
antoniocasagrande-airia wants to merge 2 commits into
antoniocasagrande-airia wants to merge 2 commits into
Conversation
… the same clock JpaWorkflowStateProvider.scheduleStep stamped scheduledStepTimestamp with Instant.now() while getDueScheduledSteps compares it against Time.currentTimeMillis(). Production behavior is unchanged (Time delegates to the system clock), but under a test time offset steps were scheduled against the wrong clock, making restart scenarios untestable with TimeOffSet. Steps scheduled during an offset run are now scheduled relative to the simulated clock, so the cumulative offsets in BrokeredUserLifecycleWorkflowTest are adjusted accordingly. Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
Workflows can already react to a client authenticating, but that event is EventType.CLIENT_LOGIN, which only the client_credentials grant emits. A public authorization-code client - what dynamic client registration produces - never raises it, so a workflow that means "disable this client if it has been idle for N days" silently degrades to "N days after it was created" for exactly the population most likely to accumulate. Add client-activity over LOGIN, CODE_TO_TOKEN and REFRESH_TOKEN, so any use of the client resets the timer. The *_ERROR variants are deliberately excluded: they carry the client id too, so counting them would let failed authentication against a dormant client keep it alive indefinitely. Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
Copilot started reviewing on behalf of
antoniocasagrande-airia
September 22, 2026 17:05
View session
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The public event is undocumented, and two supported activity event paths lack integration coverage.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds client activity tracking for workflows and aligns workflow scheduling with Keycloak’s offset-aware clock.
Changes:
- Adds
client-activityfor successful login, code exchange, and token refresh events. - Adds activation/reset and failed-login integration coverage.
- Fixes cumulative scheduling under time offsets.
| File | Description |
|---|---|
BrokeredUserLifecycleWorkflowTest.java |
Updates cumulative time offsets. |
ClientActivityWorkflowTest.java |
Tests client activity workflow behavior. |
WorkflowEventProviderFactory |
Registers the new provider. |
JpaWorkflowStateProvider.java |
Uses the offset-aware clock. |
ClientActivityWorkflowEventProvider.java |
Defines qualifying activity events. |
ClientActivityWorkflowEventFactory.java |
Exposes the client-activity event. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+44
to
+45
| @Test | ||
| public void testActivateWorkflowOnClientActivity() { |
|
|
||
| public class ClientActivityWorkflowEventFactory implements WorkflowEventProviderFactory<WorkflowEventProvider> { | ||
|
|
||
| public static final String ID = "client-activity"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #51595.
Workflows can already react to a client authenticating, but that event is
EventType.CLIENT_LOGIN, which only theclient_credentialsgrant emits. A public authorization-code client — what dynamic client registration produces — never raises it. So a CLIENTS workflow meaning "disable this client if it has been idle for N days" silently degrades to "N days after it was created" for exactly the population most likely to accumulate.This adds
client-activityoverLOGIN,CODE_TO_TOKENandREFRESH_TOKEN, so any use of the client resets the timer.The
*_ERRORvariants are deliberately excluded. They carry the client id too, so counting them would let failed authentication against a dormant client keep it alive indefinitely — a property worth stating explicitly, since it is the kind of thing that looks like an oversight later.The first commit is a separate defect
JpaWorkflowStateProviderschedules steps withInstant.now()while the due-check queries againstTime.currentTimeMillis():Under any time offset the due-check moves and the schedule does not, so steps fire at the wrong time. This is independent of the event provider and affects existing workflows; it is first here because the activity test cannot express "the timer resets on use" without both sides agreeing on a clock. Happy to split it into its own PR if you would rather review it separately.
It also changes
BrokeredUserLifecycleWorkflowTest's offsets from 5/10/10 to 5/15/25. That test was passing for the wrong reason: with scheduling on the real clock the offsets were not actually cumulative. They are now, and the comment there says so.Testing
New integration test covering activation on use and the reset behaviour, plus a case pinning that failed logins do not activate.
Verified locally:
model/jpacompiles,tests/basetest-compiles, andmvn spotless:check -pl model/jpais clean. I have not run the integration test against a server locally — it is written to the same shape as the sibling activation tests.Context: this was originally part of #51629, which I have closed since the client-attribute condition it also carried is superseded by #52189. #52189 does not include an activity event, so this half is still open and is here on its own.