Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
JAX-RS 409 exceptions receive an inconsistent problem type, and paths containing matrix parameters can incorrectly fall back to legacy error responses.
2 open issues
What changed in this PR
Introduces RFC 9457 Problem Details for Admin API v2, addressing #50671 by giving clients a consistent error format and stable problem identifiers.
Changes:
- Adds centralized error formatting, structured validation violations, and problem-type mappings.
- Updates the admin CLI, OpenAPI schema, and documentation for the new format.
- Adds error-response tests and migrates existing validation and authorization assertions.
| File | Description |
|---|---|
| services/src/main/java/org/keycloak/services/error/KeycloakErrorHandler.java | Routes v2 errors to the optional formatter. |
| services/src/main/java/org/keycloak/services/error/AdminApiV2ErrorFo 8000 rmatter.java | Defines the formatter interface. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/validation/PutClientValidationTest.java | Checks structured PUT errors and UUID conflicts. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/validation/PostClientValidationTest.java | Checks structured POST validation errors. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/validation/PatchClientValidationTest.java | Checks validation and invalid-patch problem types. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/validation/AbstractClientValidationTest.java | Adds violation matchers and updates shared assertions. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/ClientApiV2Test.java | Migrates client API error assertions. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/ClientApiV2ErrorResponsesTest.java | Adds HTTP error-format integration coverage. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/client/v2/ClientApiV2AuthorizationTest.java | Verifies forbidden problem responses. |
| rest/admin-v2/tests/src/test/java/org/keycloak/tests/admin/cli/v2/KcAdmV2ClientCLITest.java | Adjusts CLI authentication-error expectations. |
| rest/admin-v2/services/src/test/java/org/keycloak/services/error/ProblemDetailErrorFormatterTest.java | Tests classification, serialization, and message protection. |
| rest/admin-v2/services/src/test/java/org/keycloak/rest/admin/api/client/DefaultClientsApiTest.java | Updates sort-validation exception expectations. |
| rest/admin-v2/services/src/main/resources/META-INF/services/org.keycloak.services.error.AdminApiV2ErrorFormatter | Registers the formatter through ServiceLoader. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/ServiceExceptionMapper.java | Removes the legacy service-exception mapper. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/ServiceException.java | Carries problem types and structured violations. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/error/ViolationExceptionResponse.java | Removes the previous validation-response model. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/error/ValidationExceptionHandler.java | Delegates validation errors to centralized handling. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/error/ProblemDetailErrorFormatter.java | Classifies and serializes problem responses. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/client/scim/OIDCClientModelSchema.java | Handles null web origins during model mapping. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/client/scim/ClientResourceTypeProvider.java | Converts service failures into typed problems. |
| rest/admin-v2/services/src/main/java/org/keycloak/services/client/scim/BaseClientModelSchema.java | Handles null redirect URIs during model mapping. |
| rest/admin-v2/services/src/main/java/org/keycloak/rest/admin/api/DefaultAdminRootV2.java | Reports the disabled API with a dedicated problem type. |
| rest/admin-v2/services/src/main/java/org/keycloak/rest/admin/api/DefaultAdminApi.java | Reports missing realms through ServiceException. |
| rest/admin-v2/services/src/main/java/org/keycloak/rest/admin/api/client/DefaultClientsApi.java | Standardizes list and creation errors. |
| rest/admin-v2/services/src/main/java/org/keycloak/rest/admin/api/client/DefaultClientApi.java | Standardizes individual-client operation errors. |
| rest/admin-v2/services/src/main/java/org/keycloak/admin/internal/openapi/OASModelFilter.java | Adds problem schemas and error responses to OpenAPI. |
| rest/admin-v2/services/pom.xml | Adds RESTEasy support for response-building unit tests. |
| rest/admin-v2/api/src/main/java/org/keycloak/services/error/ProblemType.java | Defines stable problem identifiers and statuses. |
| rest/admin-v2/api/src/main/java/org/keycloak/services/error/ProblemDetail.java | Defines the shared problem and violation models. |
| js/libs/keycloak-admin-client/openapi.json | Updates the generated API error contract. |
| integration/client-cli/admin-cli/src/main/java/org/keycloak/client/cli/util/HeadersBodyStatus.java | Displays problem details and structured violations. |
| docs/guides/admin-api/admin-api-v2.adoc | Documents the error format and problem catalogue. |
| docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc | Explains error-format and conflict-status migration changes. |
Review effort: Balanced
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.model.infinispan.EmbeddedInfinispanSplitBrainTest#testRevokedTokensReloadedOnMergeEventKeycloak CI - Store Model Tests |
aa500e6 to
9f1fb24
Compare
|
@keycloak/cloud-native let me know if there are any concerns with the appr 10000 oach before I refine it further. |
|
Based upon our call today, I'll move forward with this PR and get it out of draft - I'd like to get some of the other pending work committed first to cut down on the number of times this will need rebased. cc @keycloak/cloud-native |
There was a problem hiding this comment.
🟡 Changes recommended
Accept-header matching ignores non-q media-type parameters, causing an explicitly acceptable unprofiled JSON response to be incorrectly rejected with HTTP 406.
1 open issue
3 resolved since last review
Review effort: Balanced
Closes: keycloak#50671 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
There was a problem hiding this comment.
🟡 Changes recommended
The malformed-body test receives 406 before parsing, non-body bad requests are mislabeled as JSON errors, and supported-database regression coverage remains unverified.
3 open issues
1 resolved since last review
Review effort: Balanced
| assertNotNull(res404.problem()); | ||
| assertEquals(ProblemType.NOT_FOUND.getType(), res404.problem().type()); | ||
|
|
||
| ResponseData res400 = execute("POST", CLIENTS_URL, true, "text/html", "application/json", "{invalid json"); |
| private static ProblemDetail fromStatus(WebApplicationException exception) { | ||
| int status = exception.getResponse().getStatus(); | ||
| if (status == Response.Status.BAD_REQUEST.getStatusCode()) { | ||
| return of(ProblemType.MALFORMED_BODY, MALFORMED_BODY_DETAIL); |
| @Test | ||
| public void duplicateClientReturns409Conflict() throws Exception { | ||
| String body = "{\"protocol\":\"openid-connect\",\"clientId\":\"" + SEED_CLIENT_ID + "\"}"; | ||
| ResponseData res = execute("POST", CLIENTS_URL, true, null, "application/json", body); |


Closes: #50671
Standardizes all error responses from Admin API v2 (
/admin/api/**) on the RFC 9457 Problem Details specification (application/problem+json), replacing previously inconsistent error shapes (OAuth 2.0 error JSON, plain string messages, and HTML error pages).Given the increasing usage of RFC 9457 within the quarkus ecosystem, that seems to be a good choice. But we can of course consider using scim or oauth style.
URNs in the
urn:keycloak:admin-api:v2:problem:namespace are used for thetypeURI reference rather than HTTP URLs (about:blankor hosted URLs) to provide stable, unambiguous, and self-contained identifiers scoped directly to Keycloak Admin API v2 without requiring dedicated external hosting or documentation infrastructure. Clients can reliably branch on thetypeURN rather than parsing human-readable error messages. Please review the types for granularity and if URLs would be preferred instead.After the yaml support was merged, the error handling is unchanged - only problem+json is emitted, not yaml errors.