-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Fire RealmAttributeUpdateEvent whenever a realm attribute changes #50799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ahus1
merged 3 commits into
keycloak:main
from
ssilvert:issue-49236-ssf-create-client-scopes
Jul 16, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
108 changes: 108 additions & 0 deletions
108
...java/org/keycloak/tests/ssf/transmitter/SsfTransmitterEnableCreatesClientScopesTests.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package org.keycloak.tests.ssf.transmitter; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.keycloak.common.Profile; | ||
| import org.keycloak.representations.idm.ClientScopeRepresentation; | ||
| import org.keycloak.ssf.Ssf; | ||
| import org.keycloak.testframework.annotations.InjectRealm; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.realm.ManagedRealm; | ||
| import org.keycloak.testframework.realm.RealmBuilder; | ||
| import org.keycloak.testframework.realm.RealmConfig; | ||
| import org.keycloak.testframework.server.DefaultKeycloakServerConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfigBuilder; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Regression test for <a href="https://github.com/keycloak/keycloak/issues/49236">keycloak#49236</a>: | ||
| * enabling the SSF transmitter on an existing realm must create the | ||
| * {@code ssf.read} and {@code ssf.manage} client scopes if they are missing. | ||
| */ | ||
| @KeycloakIntegrationTest(config = SsfTransmitterEnableCreatesClientScopesTests.SsfServerConfig.class) | ||
| public class SsfTransmitterEnableCreatesClientScopesTests { | ||
|
|
||
| @InjectRealm(config = SsfDisabledRealm.class) | ||
| ManagedRealm realm; | ||
|
|
||
| @Test | ||
| public void testEnablingTransmitterCreatesMissingClientScopes() { | ||
|
|
||
| // The realm was created while the SSF feature was already enabled, so the | ||
| // scopes exist from realm creation. Delete them to simulate a realm that | ||
| // was created before the SSF feature was turned on. | ||
| deleteClientScopeIfPresent(Ssf.SCOPE_SSF_READ); | ||
| deleteClientScopeIfPresent(Ssf.SCOPE_SSF_MANAGE); | ||
|
|
||
| Assertions.assertNull(findClientScope(Ssf.SCOPE_SSF_READ), "precondition: ssf.read should be absent"); | ||
| Assertions.assertNull(findClientScope(Ssf.SCOPE_SSF_MANAGE), "precondition: ssf.manage should be absent"); | ||
|
|
||
| // Enable the SSF transmitter through a regular realm update, like the admin console does | ||
| realm.updateWithCleanup(r -> r.attribute(Ssf.SSF_TRANSMITTER_ENABLED_KEY, "true")); | ||
|
|
||
| ClientScopeRepresentation readScope = findClientScope(Ssf.SCOPE_SSF_READ); | ||
| ClientScopeRepresentation manageScope = findClientScope(Ssf.SCOPE_SSF_MANAGE); | ||
|
|
||
| Assertions.assertNotNull(readScope, "ssf.read client scope should be created when the transmitter is enabled"); | ||
| Assertions.assertNotNull(manageScope, "ssf.manage client scope should be created when the transmitter is enabled"); | ||
|
|
||
| // The scopes must be registered as optional realm client scopes so receivers have to request them explicitly | ||
| List<String> optionalScopeNames = realm.admin().getDefaultOptionalClientScopes().stream() | ||
| .map(ClientScopeRepresentation::getName) | ||
| .toList(); | ||
| Assertions.assertTrue(optionalScopeNames.contains(Ssf.SCOPE_SSF_READ), "ssf.read should be an optional client scope"); | ||
| Assertions.assertTrue(optionalScopeNames.contains(Ssf.SCOPE_SSF_MANAGE), "ssf.manage should be an optional client scope"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testReenablingTransmitterRestoresDeletedClientScopes() { | ||
|
|
||
| // Start with the transmitter enabled and the scopes present | ||
| realm.updateWithCleanup(r -> r.attribute(Ssf.SSF_TRANSMITTER_ENABLED_KEY, "true")); | ||
|
|
||
| // Admin disables the transmitter and removes the scopes | ||
| realm.updateWithCleanup(r -> r.attribute(Ssf.SSF_TRANSMITTER_ENABLED_KEY, "false")); | ||
| deleteClientScopeIfPresent(Ssf.SCOPE_SSF_READ); | ||
| deleteClientScopeIfPresent(Ssf.SCOPE_SSF_MANAGE); | ||
|
|
||
| // Re-enabling must bring the scopes back | ||
| realm.updateWithCleanup(r -> r.attribute(Ssf.SSF_TRANSMITTER_ENABLED_KEY, "true")); | ||
|
|
||
| Assertions.assertNotNull(findClientScope(Ssf.SCOPE_SSF_READ), "ssf.read client scope should be re-created"); | ||
| Assertions.assertNotNull(findClientScope(Ssf.SCOPE_SSF_MANAGE), "ssf.manage client scope should be re-created"); | ||
| } | ||
|
|
||
| private ClientScopeRepresentation findClientScope(String name) { | ||
| return realm.admin().clientScopes().findAll().stream() | ||
| .filter(scope -> name.equals(scope.getName())) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
|
|
||
| private void deleteClientScopeIfPresent(String name) { | ||
| ClientScopeRepresentation scope = findClientScope(name); | ||
| if (scope != null) { | ||
| realm.admin().clientScopes().get(scope.getId()).remove(); | ||
| } | ||
| } | ||
|
|
||
| public static class SsfServerConfig extends DefaultKeycloakServerConfig { | ||
| @Override | ||
| public KeycloakServerConfigBuilder configure(KeycloakServerConfigBuilder config) { | ||
| KeycloakServerConfigBuilder configured = super.configure(config); | ||
| config.features(Profile.Feature.SSF); | ||
| return configured; | ||
| } | ||
| } | ||
|
|
||
| public static class SsfDisabledRealm implements RealmConfig { | ||
| @Override | ||
| public RealmBuilder configure(RealmBuilder realm) { | ||
| // Intentionally no ssf.transmitterEnabled attribute — the realm starts | ||
| // with the transmitter disabled, like a realm created before SSF was adopted | ||
| return realm.name("ssf-enable-scopes"); | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.