8000 Fix #51594: Add has-client-attribute condition and align client-created workflow event timing by tusharjamunkar · Pull Request #52189 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Fix #51594: Add has-client-attribute condition and align client-created workflow event timing - #52189

Open
tusharjamunkar wants to merge 2 commits into
keycloak:mainfrom
tusharjamunkar:fix-client-created-workflow-51594
Open

tusharjamunkar wants to merge 2 commits into
keycloak:mainfrom
tusharjamunkar:fix-client-created-workflow-51594

Conversation

@tusharjamunkar
@tusharjamunkar tusharjamunkar commented Aug 28, 2026 •
Copy link
Copy Markdown

Closes #51594

Follow-up issue: #52958

Description

Event-based workflow activation for on: client-created previously evaluated conditions against a client that was not yet populated because ClientCreatedWorkflowEventProvider listened on the low-level ProviderEvent (ClientModel.ClientCreationEvent) fired in JpaRealmProvider.addClient() before attributes and representations were applied.

This pull request resolves this timing issue by:

  1. Aligning ClientCreatedWorkflowEventProvider with UserCreatedWorkflowEventProvider by listening on AdminEvent (ResourceType.CLIENT + OperationType.CREATE) and Event (EventType.CLIENT_REGISTER).
  2. Ensuring client creation events only fire after client models are fully populated, client policies are triggered, and final validation has succeeded.
  3. Introducing the new built-in has-client-attribute condition provider for workflows to allow evaluating client-scoped attributes.

Key Changes

  • Event Alignment: ClientCreatedWorkflowEventProvider now listens to AdminEvent (ResourceType.CLIENT + OperationType.CREATE) and Event (EventType.CLIENT_REGISTER), ensuring client attributes and representations are fully populated before condition evaluation.
  • New Built-in Condition has-client-attribute:
    • Implemented ClientAttributeWorkflowConditionProvider & ClientAttributeWorkflowConditionFactory.
    • Supports single-value properties format (has-client-attribute(attribute-name:expected-value) or has-client-attribute(attribute-name:) to check existence).
    • Implements toPredicate for scheduled workflow scans with database-specific criteria queries (including Oracle DBMS_LOB.COMPARE and PostgreSQL substr(VALUE, 1, 255) index optimization on IDX_CLIENT_ATT_BY_NAME_VALUE).
    • Documented under Client functions in defining-conditions.adoc.
  • Event Emission Timing (Admin API v1): Relocated adminEvent.operation(OperationType.CREATE)...success() in ClientsResource to after client policy execution (AdminClientRegisteredContext) and validation. This guarantees that rejected creations (e.g. blocked by client policies) do not emit spurious CREATE events to any EventListenerProvider.
  • Admin API v2 Support: Enabled post-population client CREATE admin event emission in DefaultClientService.fireAdminEvent with exact resource path (clients/v2/{uuid}), ensuring Admin API v2 creations trigger on: client-created workflows. The kc.admin-v2.client-service.events.enabled flag is retained for non-CREATE operations to prevent duplicate events.
  • Partial Import Resource Mapping: Mapped PartialImportResult resource types to corresponding AdminEvent ResourceTypes in RealmAdminResource, enabling on: client-created workflows during partial import.
  • DCR Event Timing: Relocated event.client(...).success() across DefaultClientRegistrationProvider, OIDCClientRegistrationProvider, EntityDescriptorClientRegistrationProvider, and AbstractPersistentClientIdMetadataDocumentProvider to after pairwise protocol mapper setup and final validation.
  • Automated Integration Tests:
    • ClientCreationWorkflowTest: Covers Admin REST API v1, Admin API v2, Dynamic Client Registration (Default & OIDC), Partial Import, and scheduled workflow scans with @DatabaseTest criteria evaluation and Awaitility synchronization.
    • AdminEventV2Test: Assertions verify exact resource paths (clients/v2/{uuid}) for created clients.

Release Notes / Changelog

  • Workflows: New Built-in Condition has-client-attribute: Workflows now provide a built-in has-client-attribute condition provider that evaluates whether a client contains a specified attribute and value (or simply checks for attribute presence). This condition is supported for both real-time event triggers and scheduled batch scans.
  • Admin Event Timing (ClientsResource): In Admin REST API v1, the CLIENT CREATE admin event is now emitted only after client policies have executed and final validation has succeeded. As a result, client creations rejected by client policies will no longer produce spurious CREATE admin events.
  • Admin API v2 Client Creation Events: Admin API v2 now emits a post-population CREATE admin event upon client creation, allowing event listeners and workflows (on: client-created) to react to clients created via the v2 API.

Related Issues

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.

Pull request overview

Updates client-created workflow activation to use admin and dynamic registration events after client population.

Changes:

  • Replaces low-level client creation event handling.
  • Adds an integration test for workflow execution after client creation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
ClientCreatedWorkflowEventProvider.java Handles admin and dynamic client registration events.
ClientCreationWorkflowTest.java Tests client-created workflow activation.

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

Comment on lines +23 to +24
public boolean supports(Event event) {
return EventType.CLIENT_REGISTER.equals(event.getType());
Comment on lines +28 to +30
public boolean supports(AdminEvent adminEvent) {
return org.keycloak.events.admin.ResourceType.CLIENT.equals(adminEvent.getResourceType())
&& OperationType.CREATE.equals(adminEvent.getOperationType());
Comment on lines +33 to +34
WorkflowRepresentation workflow = WorkflowRepresentation.withName("client-created-workflow")
.onEvent(ClientCreatedWorkflowEventFactory.ID)
Copilot AI review requested due to automatic review settings August 28, 2026 16:14
@tusharjamunkar
Copy link
Copy Markdown
Author

Updated with latest review hardening:

  • Moved adminEvent.CREATE.success() in ClientsResource to after ValidationUtil.validateClient and AdminClientRegisteredContext.
  • Moved event.CLIENT_REGISTER.success() in AbstractPersistentClientIdMetadataDocumentProvider to after pairwise protocol mappers and validation.
  • Verified compilation across model/jpa and services modules with Maven (BUILD SUCCESS).

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

model/jpa/src/main/java/org/keycloak/models/workflow/events/ClientCreatedWorkflowEventProvider.java:24

  • CLIENT_REGISTER is still published too early for the standard dynamic-registration paths: AbstractClientRegistrationProvider.create() calls success() before OIDCClientRegistrationProvider adds pairwise sub-mappers and performs final validation (lines 99–105), and before DefaultClientRegistrationProvider performs final validation (lines 53–54). Consequently, this new listener can evaluate conditions and run steps against an incompletely configured client; move the success notification after each registration path's post-processing, as this PR does for CIMD.
    public boolean supports(Event event) {
        return EventType.CLIENT_REGISTER.equals(event.getType());

tests/base/src/test/java/org/keycloak/tests/workflow/activation/ClientCreationWorkflowTest.java:34

  • This regression test adds an attribute but never adds a workflow condition that reads it, so it only verifies step timing and can still pass if an event is emitted after enabled is copied but before attributes are available. Add a client-scoped test condition and attach it with onCondition(...) so the behavior reported in #51594 is exercised directly.
        WorkflowRepresentation workflow = WorkflowRepresentation.withName("client-created-workflow")
                .onEvent(ClientCreatedWorkflowEventFactory.ID)

Copilot AI review requested due to automatic review settings August 28, 2026 16:24
@tusharjamunkar
Copy link
Copy Markdown
Author

Further hardened dynamic client registration (DCR) event emission timing:

  • Removed early event.success() from AbstractClientRegistrationProvider.create().
  • Added event.success() after post-processing (e.g. pairwise protocol mappers) and final validateClient() across:
    • DefaultClientRegistrationProvider
    • OIDCClientRegistrationProvider
    • EntityDescriptorClientRegistrationProvider
  • Rebuilt with Maven: BUILD SUCCESS across all modules.

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment on lines +23 to +24
public boolean supports(Event event) {
return EventType.CLIENT_REGISTER.equals(event.getType());
Copilot AI review requested due to automatic review settings August 28, 2026 16:38
@tusharjamunkar
Copy link
Copy Markdown
Author

Added Dynamic Client Registration test case:

  • testActivateWorkflowOnDynamicClientRegistration in ClientCreationWorkflowTest.java explicitly exercises the EventType.CLIENT_REGISTER branch via oauth.clientRegistration().
  • Renamed admin test case to testActivateWorkflowOnAdminClientCreation to provide complete coverage for both registration/creation mechanisms.

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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

tests/base/src/test/java/org/keycloak/tests/workflow/activation/ClientCreationWorkflowTest.java:71

  • The dynamic-registration case also activates an unconditional workflow, so it does not verify that CLIENT_REGISTER is emitted only after client attributes are visible to conditions. Make this workflow depend on a client-scoped condition matching custom-attr=dcr-val so this path directly guards the issue being fixed.
                .onEvent(ClientCreatedWorkflowEventFactory.ID)

public void testActivateWorkflowOnAdminClientCreation() {
// create the workflow that triggers on client creation
WorkflowRepresentation workflow = WorkflowRepresentation.withName("admin-client-created-workflow")
.onEvent(ClientCreatedWorkflowEventFactory.ID)
Copilot AI review requested due to automatic review settings August 28, 2026 16:48
@tusharjamunkar
Copy link
Copy Markdown
Author

Added has-client-attribute condition provider and comprehensive condition verification:

  • Implemented ClientAttributeWorkflowConditionProvider & ClientAttributeWorkflowConditionFactory (has-client-attribute) for ResourceType.CLIENTS.
  • Updated ClientCreationWorkflowTest.java with condition-gated workflows:
    • Verifies that clients matching the attribute condition trigger workflow activation and execute steps.
    • Verifies that clients not matching the condition are skipped.
    • Covers both Admin REST API and Dynamic Client Registration paths.
  • Built & verified with Maven: BUILD SUCCESS.

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.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Suppressed comments (1)

model/jpa/src/main/java/org/keycloak/models/workflow/conditions/ClientAttributeWorkflowConditionProvider.java:79

  • This rejects the key=value properties syntax used by the analogous has-user-attribute condition and documented for workflow attributes, even though Properties.load below supports it. Keep only the null/blank validation so both standard properties separators remain valid.
        if (!expectedAttribute.contains(":")) {
            throw new WorkflowInvalidStateException("workflowConditionAttributeInvalid", expectedAttribute);
        }

Comment on lines +68 to +69
public Predicate toPredicate(CriteriaBuilder cb, CriteriaQuery<String> query, Root<?> path) {
return null;
@@ -18,4 +18,5 @@
org.keycloak.models.workflow.conditions.GroupMembershipWorkflowConditionFactory
org.keycloak.models.workflow.conditions.IdentityProviderWorkflowConditionFactory
org.keycloak.models.workflow.conditions.UserAttributeWorkflowConditionFactory
org.keycloak.models.workflow.conditions.ClientAttributeWorkflowConditionFactory
Copilot AI review requested due to automatic review settings August 28, 2026 16:56
@tusharjamunkar
Copy link
Copy Markdown
Author

Completed final enhancements for has-client-attribute:

  • Implemented toPredicate(...) against ClientAttributeEntity for criteria query generation in scheduled workflows.
  • Accepted both key=value and key:value standard Java properties formatting.
  • Documented has-client-attribute under Client functions in defining-conditions.adoc.
  • Verified compilation with Maven: BUILD SUCCESS.

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

}

@Override
public Predicate toPredicate(CriteriaBuilder cb, CriteriaQuery<String> query, Root<?> path) {
Copilot AI review requested due to automatic review settings August 28, 2026 17:05
@tusharjamunkar
Copy link
Copy Markdown
Author

Added scheduled workflow criteria predicate test coverage:

  • Added testScheduledWorkflowWithClientAttributeCondition to ClientCreationWorkflowTest.java.
  • Verifies that toPredicate(...) against ClientAttributeEntity correctly selects pre-existing matching clients during scheduled workflow scans while skipping non-matching clients.
  • Built & verified with Maven: BUILD SUCCESS.

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Comment on lines +81 to +92
Subquery<Long> matchingCountSubquery = query.subquery(Long.class);
Root<ClientAttributeEntity> attrRoot = matchingCountSubquery.from(ClientAttributeEntity.class);
matchingCountSubquery.select(cb.count(attrRoot));
matchingCountSubquery.where(
cb.and(
cb.equal(attrRoot.get("client").get("id"), path.get("id")),
cb.equal(attrRoot.get("name"), attributeName),
cb.equal(attrRoot.get("value"), valuePart)
)
);

return cb.greaterThan(matchingCountSubquery, 0L);
Comment on lines +156 to +165
// 4. Trigger scheduled steps execution (evaluates toPredicate)
runScheduledSteps(Duration.ZERO);

// 5. Assert matching client is selected by criteria predicate and disabled
ClientResource matchingResource = managedRealm.admin().clients().get(matchingId);
assertThat(matchingResource.toRepresentation().isEnabled(), is(false));

// 6. Assert non-matching client is not selected and remains enabled
ClientResource nonMatchingResource = managedRealm.admin().clients().get(nonMatchingId);
assertThat(nonMatchingResource.toRepresentation().isEnabled(), is(true));
@@ -18,4 +18,5 @@
org.keycloak.models.workflow.conditions.GroupMembershipWorkflowConditionFactory
org.keycloak.models.workflow.conditions.IdentityProviderWorkflowConditionFactory
org.keycloak.models.workflow.conditions.UserAttributeWorkflowConditionFactory
org.keycloak.models.workflow.conditions.ClientAttributeWorkflowConditionFactory
@antoniocasagrande-airia antoniocasagrande-airia left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: the new files are missing the Apache license header and trailing newlines.

@@ -254,6 +252,8 @@ public ClientModel createClientModel(final ClientRepresentation rep) {
session.getContext().setClient(clientModel);
session.clientPolicy().triggerOnEvent(new AdminClientRegisteredContext(clientModel, auth.adminAuth()));

adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), clientModel.getId()).representation(rep).success();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This relocation changes behavior for every EventListenerProvider, not just workflows: a creation rejected by validation or client policy no longer emits the CREATE event (previously it did), and all listeners see the new ordering. The PR description should state that. Also, other producers of CLIENT+CREATE admin events (e.g. partial import) will now activate on: client-created workflows — intended?

public void close() {
}

public static String[] parseKeyValuePair(String keyValuePair) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Byte-identical to UserAttributeWorkflowConditionProvider.parseKeyValuePair (also public static) — reuse that instead of a second copy. One divergence to settle: that condition splits the value on commas for multi-value matching, this one compares literally, so key:v1,v2 behaves differently between the two. Either support the list form or state single-value in the doc row.

@tusharjamunkar
tusharjamunkar force-pushed the fix-client-created-workflow-51594 branch from c48fcbc to 7a5f32f Compare August 29, 2026 04:57
@tusharjamunkar
Copy link
Copy Markdown
Author

Refined Admin API v2 resource path and OIDC DCR client lookup:

  • Admin API v2 Resource Path: In DefaultClientService.fireAdminEvent, used representation.getUuid() for OperationType.CREATE (matching internal workflow dispatch expectation) and preserved the existing request URI for updates/patches.
  • OIDC DCR Test Resolution: In ClientCreationWorkflowTest.java, resolved the client representation via clients().findByClientId(...) before invoking clients().get(id).

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.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

rest/admin-v2/services/src/main/java/org/keycloak/services/client/DefaultClientService.java:433

  • The former feature flag guarded all Admin API v2 events, but this else now emits UPDATE and DELETE events unconditionally. That reintroduces the duplicate admin events the method comment says the flag avoids; keep CREATE unconditional for workflow activation while retaining the flag for non-CREATE operations.
        } else {
            adminEventBuilder
                    .operation(operationType)
                    .resourcePath(session.getContext().getUri())
                    .representation(representation)
                    .success();
        }

if (OperationType.CREATE.equals(operationType)) {
adminEventBuilder
.operation(operationType)
.resourcePath(session.getContext().getUri(), representation.getUuid())
…before client is populated

- Align ClientCreatedWorkflowEventProvider with AdminEvent (ResourceType.CLIENT + OperationType.CREATE) and Event (EventType.CLIENT_REGISTER) rather than premature ProviderEvent, ensuring client attributes and representations are fully populated before condition evaluation.
- Move event.success() after final validation across ClientsResource, DefaultClientRegistrationProvider, OIDCClientRegistrationProvider, EntityDescriptorClientRegistrationProvider, and AbstractPersistentClientIdMetadataDocumentProvider. This ensures rejected creations do not emit invalid CREATE events to EventListenerProviders.
- Enable post-population client CREATE admin event emission in Admin API v2 DefaultClientService while retaining property flag for non-CREATE operations.
- Map PartialImportResult resource types to corresponding AdminEvent ResourceTypes in RealmAdminResource so partial-import client creations emit CLIENT+CREATE admin events, and update PartialImportUserTest assertions accordingly.
- Implement ClientAttributeWorkflowConditionProvider & ClientAttributeWorkflowConditionFactory (has-client-attribute) supporting single-value properties format and database-specific criteria predicates (including Oracle DBMS_LOB.COMPARE and PostgreSQL expression index optimizations).
- Add Client functions documentation for has-client-attribute in defining-conditions.adoc.
- Add comprehensive automated integration tests in ClientCreationWorkflowTest for Admin REST API, Dynamic Client Registration (DCR & OIDC), Partial Import, and scheduled workflow scans with DatabaseTest annotation and Awaitility synchronization.

Signed-off-by: tusharjamunkar <tusharjamunkar@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 29, 2026 05:08
@tusharjamunkar
tusharjamunkar force-pushed the fix-client-created-workflow-51594 branch from 7a5f32f to 28d2327 Compare August 29, 2026 05:08
@tusharjamunkar
Copy link
Copy Markdown
Author

Updated Admin API v2 event flag scoping and test path assertion:

  • Flag Scoping: In DefaultClientService.fireAdminEvent, kept CREATE event emission unconditional (for client workflow activation) while retaining the kc.admin-v2.client-service.events.enabled property flag for non-CREATE operations (UPDATE/DELETE) to prevent duplicate events.
  • Test Assertion: Updated AdminEventV2Test.createClientFiresV2Event to assert that the event path starts with clients/v2.

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.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@sguilhen
Copy link
Copy Markdown
Contributor

Hi @tusharjamunkar , thanks for working on this!

I went through the PR and the review history. Most of Copilot findings from earlier rounds look addressed in the current squashed commit (event-timing relocation across ClientsResource/DCR providers/CIMD, has-client-attribute's toPredicate implementation with Oracle/Postgres handling, partial-import resource-type mapping, the v2 UUID resource-path bug, the OIDC DCR test lookup bug). A few things worth resolving before merge:

  1. Admin API v2 workflow activation is untested. The PR explicitly calls out enabling post-population CREATE event emission in DefaultClientService as a key change, and this was one of the more serious regressions Copilot flagged (v2 creations previously fired neither event Workflows listens to). AdminEventV2Test checks the raw event shape, but ClientCreationWorkflowTest never creates a client via the v2 API and asserts a client-created workflow actually fires. Since this is the PR's own claimed fix, let's add that test here rather than deferring it.

  2. SAML (EntityDescriptorClientRegistrationProvider) and CIMD (AbstractPersistentClientIdMetadataDocumentProvider) paths have no workflow-activation coverage, even though their event timing was also relocated. These are more niche paths than v2, so I'm fine deferring if you will, but let's open a follow-up issue and link it here rather than leaving it implicit. Or add a couple of tests for these paths.

  3. On has-client-attribute being scope creep: I'd normally push to split this into its own PR, but the regression test genuinely needs a client-scoped condition to prove the fix. Without one, we can only show attributes eventually persist, not that they were visible at condition-evaluation time (Copilot's original point). Splitting it out would leave one PR untestable without the other. Suggest keeping it here, but updating the PR title/description to explicitly frame it as introducing a new built-in condition, not just test scaffolding so it gets proper changelog/release-note visibility.

  4. Minor: AdminEventV2Test.createClientFiresV2Event was loosened from an exact path match to startsWith("clients/v2") to accommodate the new {uuid} suffix. That would still pass with a malformed suffix (e.g. clients/v2/null). Suggest asserting the full expected path ("clients/v2/" + createdClientUuid) instead.

The ClientsResource admin-event relocation (now firing only after client-policy execution) also changes behavior for every EventListenerProvider, not just Workflows. IMO that's the correct fix (a rejected creation shouldn't emit a CREATE event at all), so just flagging it for the changelog rather than as a concern. Maybe add something to the release notes?

@sguilhen sguilhen 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.

See my last comment for a list of suggestions.

10BC8
Copilot AI review requested due to automatic review settings September 18, 2026 16:51
@tusharjamunkar tusharjamunkar changed the title Fix #51594: Workflows on: client-created conditions evaluated before client is populated Fix #51594: Add has-client-attribute condition and align client-created workflow event timing Sep 18, 2026
@tusharjamunkar
Copy link
Copy Markdown
Author

Hi @sguilhen,

Thank you for the detailed and constructive review! I have addressed all points from your feedback:

  1. Admin API v2 Workflow Test: Added testActivateWorkflowOnAdminV2ClientCreationWithCondition in ClientCreationWorkflowTest.java, which runs under Profile.Feature.CLIENT_ADMIN_API_V2, creates a client via the Admin API v2 endpoint (clients/v2), and verifies that the on: client-created workflow activates and disables the client when the condition matches, while non-matching clients remain enabled.
  2. Follow-Up Issue for SAML & CIMD: Opened Add workflow-activation test coverage for SAML and CIMD client registration paths #52958 ("Add workflow-activation test coverage for SAML and CIMD client registration paths") and linked it in the PR description.
  3. Framing of has-client-attribute: Updated the PR title and description to explicitly highlight introducing the has-client-attribute built-in condition provider, its syntax, and its database-specific toPredicate optimization.
  4. Tightened Event Path Assertion: Updated AdminEventV2Test.createClientFiresV2Event to assert the exact full path ("clients/v2/" + samlClientUuid).
  5. Release Notes: Added release note callouts in the PR description for has-client-attribute, the Admin API v2 client creation event emission, and the ClientsResource admin event relocation (ensuring client creations rejected by policies do not emit spurious CREATE events).

The updated commits are pushed and ready for your re-review!

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Comment on lines +23 to 31
public boolean supports(Event event) {
return EventType.CLIENT_REGISTER.equals(event.getType());
}

@Override
protected String resolveResourceId(ProviderEvent providerEvent) {
if (providerEvent instanceof ClientModel.ClientCreationEvent cce) {
return cce.getCreatedClient().getId();
}
return null;
public boolean supports(AdminEvent adminEvent) {
return org.keycloak.events.admin.ResourceType.CLIENT.equals(adminEvent.getResourceType())
&& OperationType.CREATE.equals(adminEvent.getOperationType());
}
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.

Checked this against ResourceType.CLIENTS.resolveResourceId in server-spi-private: it already resolves the public clientId to the internal UUID generically via findClientResourceId, the same way USERS resolves through event.getUserId(). ClientCreatedWorkflowEventProvider doesn't need its own resolution logic. Closing this one out.

return false;
}

String[] parsedKeyValuePair = UserAttributeWorkflowConditionProvider.parseKeyValuePair(expectedAttribute);
public Predicate toPredicate(CriteriaBuilder cb, CriteriaQuery<String> query, Root<?> path) {
validate();

String[] parsedKeyValuePair = UserAttributeWorkflowConditionProvider.parseKeyValuePair(expectedAttribute);
Comment on lines +99 to +100
EntityManager em = session.getProvider(JpaConnectionProvider.class).getEntityManager();
String dbProductName = em.unwrap(Session.class).doReturningWork(connection -> connection.getMetaData().getDatabaseProductName());
Comment on lines +421 to +427
if (OperationType.CREATE.equals(operationType)) {
adminEventBuilder
.operation(operationType)
.resourcePath(session.getContext().getUri(), representation.getUuid())
.representation(representation)
.success();
} else if (Boolean.parseBoolean(System.getProperty("kc.admin-v2.client-service.events.enabled", "false"))) {
@antoniocasagrande-airia
Copy link
Copy Markdown

One path that I think is still uncovered: ClientResourceTypeProvider (the SCIM v2
client path) has the same kc.admin-v2.client-service.events.enabled gate around its
fireAdminEvent, and it isn't in this PR. If the v2 follow-up issue is being opened
for SAML and CIMD anyway, that one probably belongs in it.

@sguilhen
sguilhen commented Dec 2, 2026
Copy link
Copy Markdown
Contributor

Summarizing where this stands, since the thread has drifted across #51594/#51595/#51629.

Delivered here: the on: client-created timing fix (admin v1/v2, DCR default+OIDC, SAML, CIMD, partial import) for #51594, plus has-client-attribute — kept bundled since the regression test needs a client-scoped condition to prove the timing fix. This also delivers the has-client-attribute half of #51595's original scope (the client-activity half remains unaddressed there, tracked separately).

Two things need action before this is ready:

  1. ClientResourceTypeProvider (SCIM v2 client path) has the same kc.admin-v2.client-service.events.enabled gating gap that DefaultClientService had before this PR. @tusharjamunkar can you fix it here, or fold it explicitly into Add workflow-activation test coverage for SAML and CIMD client registration paths #52958's scope? Right now it's neither.
  2. Branch has conflicts with main, needs a rebase before further review.

Minor, non-blocking: has-client-attribute reuses UserAttributeWorkflowConditionProvider#parseKeyValuePair, which has known Properties-syntax edge cases (comment-prefixed key, multi-line/repeated-key handling) — already being fixed for both conditions in #53081. That PR should probably land first, or this one should rebase onto it once merged, so has-client-attribute ships with the corrected validation from day one rather than inheriting the bug and needing a second pass.

Out of scope for this PR, tracked on #51595: the client-activity event provider.

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.

Workflows: on: client-created conditions are evaluated before the client is populated, so they can never match

5 participants

0