1

首先,我想为打字错误道歉,在平板电脑上写东西。

我正在构建一个由 Keycloak 服务保护的 springboot 应用程序。我需要我的最终用户能够通过我的前端创建一个 keycloak 用户,所以我尝试通过 keycloak 管理依赖项来构建它

<dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-admin-client</artifactId>
            <version>11.0.2</version>
        </dependency>

我快完成了,但越来越HTTP 409讨厌

    private void createClientRole(String clientRole, Keycloak kc) {
        RoleRepresentation clientRoleRepresentation = new RoleRepresentation();
        clientRoleRepresentation.setName(clientRole);
        clientRoleRepresentation.setClientRole(true);
        kc.realm(this.realm).clients().findByClientId(clientId).forEach(clientRepresentation ->
kc.realm(this.realm).clients().get(clientRepresentation.getId()).roles().create(clientRoleRepresentation)
        );//<== Here
    }

没有进一步的解释,不知道那里发生了什么。任何想法?

亲切的问候,罗萨里奥

4

1 回答 1

3

HTTP 409响应意味着冲突:

由于与目标资源的当前状态冲突,无法完成请求。此代码用于用户可能能够解决冲突并重新提交请求的情况。

您应该检查 Keycloak 服务器日志以获取更多详细信息。我敢打赌,具有该特定名称的角色已经存在,这是 409 响应的根本原因。这是一个盲目的猜测——你没有发布任何 Keycloak 服务器错误日志,所以如果我在这一点上错了,请不要怪我。

于 2020-09-13T21:54:36.800 回答