Skip to content

Fire RealmAttributeUpdateEvent whenever a realm attribute changes#50799

Merged
ahus1 merged 3 commits into
keycloak:mainfrom
ssilvert:issue-49236-ssf-create-client-scopes
Jul 16, 2026
Merged

Fire RealmAttributeUpdateEvent whenever a realm attribute changes#50799
ahus1 merged 3 commits into
keycloak:mainfrom
ssilvert:issue-49236-ssf-create-client-scopes

Conversation

@ssilvert

Copy link
Copy Markdown
Contributor

SSF listens for this event to create the ssf.read/ssf.manage client scopes when the SSF transmitter is switched on for an existing realm. But the event was only published by setAdminPermissionsEnabled, never by the generic RealmAdapter.setAttribute path that realm updates from the admin console go through.

setAttribute now publishes the event when the attribute value actually changes (no event on no-op writes), so re-saving a realm does not re-fire events for unchanged attributes.

Fixes #49236

Assisted-by: claude-fable-5

SSF listens for this event to create the ssf.read/ssf.manage client
scopes when the SSF transmitter is switched on for an existing realm.
But the event was only published by setAdminPermissionsEnabled, never
by the generic RealmAdapter.setAttribute path that realm updates from
the admin console go through.

setAttribute now publishes the event when the attribute value actually
changes (no event on no-op writes), so re-saving a realm does not
re-fire events for unchanged attributes.

Fixes keycloak#49236

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
Assisted-by: claude-fable-5
Copilot AI review requested due to automatic review settings July 10, 2026 18:50
@ssilvert
ssilvert requested a review from a team as a code owner July 10, 2026 18:50

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

Publishes realm attribute update events for changed JPA attributes, enabling SSF scope creation for existing realms.

Changes:

  • Suppresses events for unchanged attribute values.
  • Adds SSF client-scope regression coverage.
  • Refactors admin-permissions event publishing.

Reviewed changes

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

File Description
model/jpa/.../RealmAdapter.java Publishes realm attribute events.
ssf/tests/.../SsfTransmitterEnableCreatesClientScopesTests.java Tests SSF scope creation and restoration.

Comment thread model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java Outdated
Comment thread model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java
Publish RealmAttributeUpdateEvent on attribute removal, avoid double-publish in setAdminPermissionsEnabled, add event contract test

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
Copilot AI review requested due to automatic review settings July 13, 2026 19:02
@ssilvert
ssilvert requested review from a team as code owners July 13, 2026 19:02

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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java Outdated
…hange

setAttribute now delegates to a private updateAttribute that reports
whether the value changed and the event was published. The explicit
repair event in setAdminPermissionsEnabled only fires when the write
was a no-op, so a real transition no longer publishes twice when no
listener creates the admin permissions client (e.g. with the
ADMIN_FINE_GRAINED_AUTHZ_V2 feature disabled).

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
Copilot AI review requested due to automatic review settings July 13, 2026 19:35

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 3 out of 3 changed files in this pull request and generated no new comments.

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

Thanks @ssilvert - LGTM.

One thing to flag: this broadens the RealmAttributeUpdateEvent surface. Previously, only setAdminPermissionsEnabled published this event for a single attribute. Now every setAttribute/removeAttribute call publishes it.

The existing listeners (JpaClientProviderFactory, SsfRealmResourceProviderFactory) all filter by attribute name, so they're fine. But custom listener implementations that react to RealmAttributeUpdateEvent without filtering by name will now fire on every attribute write, which can be frequent during realm imports or admin console saves.

This probably warrants an upgrading note mentioning the change in behavior, so that users with custom event listeners can add attribute-name filtering if needed.

@ahus1
ahus1 merged commit 2d8c0fb into keycloak:main Jul 16, 2026
92 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.

SSF: Client scopes ssf.read and ssf.manage not created when SSF enabled for existing realm

4 participants