Integrate client secret rotation with client admin api v2 - #51615
Open
rmartinc wants to merge 1 commit into
Open
Integrate client secret rotation with client admin api v2#51615rmartinc wants to merge 1 commit into
rmartinc wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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, matchingClientResource.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>
| } | ||
| 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)); |
Member
There was a problem hiding this comment.
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);
}
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.
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.