Skip to content

Integrate client secret rotation with client admin api v2 - #51615

Open
rmartinc wants to merge 1 commit into
keycloak:mainfrom
rmartinc:issue-51535
Open

Integrate client secret rotation with client admin api v2#51615
rmartinc wants to merge 1 commit into
keycloak:mainfrom
rmartinc:issue-51535

Conversation

@rmartinc

Copy link
Copy Markdown
Contributor

Closes #51535
Closes #51527

Adding the client secret rotation bits for the admin API v2. I also needed to change the builders to make the test work with jackson3 (configuration for policies and profiles was not serialized OK). A simple test class added to check the rotation works OK with the admin API v2.

@rmartinc
rmartinc requested a review from a team as a code owner August 11, 2026 11:08
Copilot AI balanced review requested due to automatic review settings August 11, 2026 11:08
@rmartinc
rmartinc requested a review from a team as a code owner August 11, 2026 11:08

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

Integrates client-secret rotation into Admin API v2 and adds supporting tests and serialization fixes.

Changes:

  • Adds rotation and stale-secret cleanup to v2 updates.
  • Updates policy configuration builders for Jackson 3.
  • Adds Admin API v2 rotation tests.

Reviewed changes

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

Show a summary per file
File Description
ClientProfileBuilder.java Updates executor configuration serialization.
ClientPolicyBuilder.java Updates condition configuration serialization.
ClientResource.java Simplifies rotation-state cleanup.
ClientApiV2ClientSecretRotationTest.java Tests v2 secret rotation behavior.
DefaultClientService.java Integrates rotation into v2 client updates.
Suppressed comments (1)

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

  • This cleanup runs before AdminClientUpdatedContext, which is the event that marks ordinary PUT/PATCH updates as rotation-enabled. An update under an active policy therefore deletes any rotated grace-period secret and resets its expiration metadata; trigger the final updated/rotation event before cleanup, matching ClientResource.java:172-176.
                        if (!Boolean.TRUE.equals(session.removeAttribute(ClientSecretConstants.CLIENT_SECRET_ROTATION_ENABLED))) {
                            OIDCClientSecretConfigWrapper.fromClientModel(model).removeClientSecretRotationInfo();
                        }

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

Closes keycloak#51535
Closes keycloak#51527

Signed-off-by: rmartinc <rmartinc@redhat.com>
Copilot AI review requested due to automatic review settings August 11, 2026 12:53

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

}
try {
executor.setConfiguration(RawJsonValue.of(JsonSerialization.mapper.readValue(JsonSerialization.mapper.writeValueAsBytes(config), JsonNode.class)));
executor.setConfiguration(JsonSerialization.mapper.readValue(JsonSerialization.mapper.writeValueAsBytes(config), RawJsonValue.class));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree this fixes the serialization in Jackson 3 test profile, but the JsonSerialization.mapper is Jackson 2 specific. I imagine something like this would be better:

diff --git a/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientPolicyBuilder.java b/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientPolicyBuilder.java
index 3aa10c5655..9968094389 100644
--- a/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientPolicyBuilder.java
+++ b/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientPolicyBuilder.java
@@ -13,7 +13,7 @@ import org.keycloak.services.clientpolicy.condition.ClientAccessTypeCondition;
 import org.keycloak.services.clientpolicy.condition.ClientScopesCondition;
 import org.keycloak.services.clientpolicy.condition.GrantTypeCondition;
 import org.keycloak.services.clientpolicy.condition.IdentityProviderCondition;
-import org.keycloak.util.JsonSerialization;
+import org.keycloak.json.KeycloakJsonMapperFactory;
 
 
 /**
@@ -94,7 +94,8 @@ public class ClientPolicyBuilder extends Builder<ClientPolicyRepresentation> {
             config = new ClientPolicyConditionConfigurationRepresentation();
         }
         try {
-            condition.setConfiguration(JsonSerialization.mapper.readValue(JsonSerialization.mapper.writeValueAsBytes(config), RawJsonValue.class));
+            var mapper = KeycloakJsonMapperFactory.mapper();
+            condition.setConfiguration(mapper.readValue(mapper.writeValueAsBytes(config), RawJsonValue.class));
         } catch(IOException e) {
             throw new IllegalArgumentException("Invalid configuration", e);
         }
diff --git a/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientProfileBuilder.java b/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientProfileBuilder.java
index 852aaf21ae..924ffa6d35 100644
--- a/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientProfileBuilder.java
+++ b/test-framework/builders/src/main/java/org/keycloak/testframework/realm/ClientProfileBuilder.java
@@ -8,7 +8,7 @@ import org.keycloak.json.RawJsonValue;
 import org.keycloak.representations.idm.ClientPolicyExecutorConfigurationRepresentation;
 import org.keycloak.representations.idm.ClientPolicyExecutorRepresentation;
 import org.keycloak.representations.idm.ClientProfileRepresentation;
-import org.keycloak.util.JsonSerialization;
+import org.keycloak.json.KeycloakJsonMapperFactory;
 
 
 /**
@@ -46,7 +46,8 @@ public class ClientProfileBuilder extends Builder<ClientProfileRepresentation> {
             config = new ClientPolicyExecutorConfigurationRepresentation();
         }
         try {
-            executor.setConfiguration(JsonSerialization.mapper.readValue(JsonSerialization.mapper.writeValueAsBytes(config), RawJsonValue.class));
+            var mapper = KeycloakJsonMapperFactory.mapper();
+            executor.setConfiguration(mapper.readValue(mapper.writeValueAsBytes(config), RawJsonValue.class));
         } catch (IOException e) {
             throw new IllegalArgumentException("Invalid configuration", e);
         }

@michalvavrik michalvavrik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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.

Admin API v2 client update does not clean up stale rotated secret attributes Admin v2 API PATCH bypasses client secret rotation policy

3 participants