【发布时间】:2019-12-07 02:44:09
【问题描述】:
我正在尝试使用 Admin REST API 在我的 Keycloak 6.0.1 系统中以编程方式管理角色和组合。根据文档,这就是我想要使用的:
https://www.keycloak.org/docs-api/6.0/rest-api/index.html#_roles_resource
马上,我的 Keycloak API 的基本 URL 似乎是:
https://example.com/auth/admin
而不是 /auth,正如文档所暗示的那样。如果我使用文档中指定的基本 URL,我会得到 404。当我通过浏览器管理安装时,通过检查 Kubernetes 管理页面的操作,我发现了这个备用 URL 结构。
无论如何,我现在使用POST /{realm}/clients/{id}/roles 端点成功地创建了角色。当我尝试使用 POST /{realm}/clients/{id}/roles/{role-name}/composites 和这样的 POST 添加复合材料时,问题就开始了:
/auth/admin/realms/REDACTED/clients/546052d9-6ba1-483e-93a5-a5fda51505b8/roles/%5ECouponAttemptsLog%25Unowned%25Write/composites
authorization: Bearer REDACTED
Content-Type: application/json
Accept: */*
Content-Length: 217
User-Agent: node-fetch/1.0 (+https://github.com/bitinn/node-fetch)
Accept-Encoding: gzip,deflate
Connection: close
Host: REDACTED
{"roles":[{"name":"^CouponAttemptsLog/id%Unowned%Write"},{"name":"^CouponAttemptsLog/code%Unowned%Write"},{"name":"^CouponAttemptsLog/eventId%Unowned%Write"},{"name":"^CouponAttemptsLog/attemptedDate%Unowned%Write"}]}
Keycloak 记录的错误信息是:
14:18:02,617 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-4884) Uncaught server error: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token
...Keycloak 返回一个没有文本的 500 响应。
据我所知,这与 Keycloak 6 API 文档中指定的预期请求形状相匹配,我不知道可能导致此反序列化失败的原因。只是为了 yuks,我尝试发送一个裸 JSON 数组作为正文,没有任何改进。
我做错了什么?我知道 Keycloak 的错误意味着它正在尝试将某些内容转换为 ArrayList ,但这是不可能的,但我不知道是什么以及为什么。
【问题讨论】: