Why am I getting a http 409 when creating an keycloak user (spring boot)?

Viewed 3226

firstly i'd Like to apologise for typos, writing thing on a tablet pc on a plain.

I'm building a springboot app secured by a Keycloak service. I need my end-user to be able to create an keycloak User via my Frontend so I've tried to build it via the keycloak admin dependency

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

I'm almost done but getting a nasty HTTP 409 on

    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
    }

There is no further explanation, don't know what's happening there. Any idea?

Kind regards, Rosario

1 Answers

HTTP 409 response means conflict:

The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request.

You should check Keycloak server logs for more details. I will bet that role with that particular name already exists and that is a root cause for 409 response. It is a blind guess - you didn't posted any Keycloak server error logs, so don't blame me if I'm wrong in this point.

Related