I've got trouble with creating users via restapi on my keycloak service again. It's creating a user but not assiging the correct role afterwards.
Figured out that the code failes on the following part
private void assignRoleToUser(String userId, String role){
Keycloak keycloak = getAdminKeycloak();
UsersResource usersResource = keycloak.realm(realm).users();
UserResource userResource = usersResource.get(userId);
ClientResource clientResource =keycloak.realm(realm).clients().get(clientId);
RoleRepresentation clientRole = clientResource.roles().get(role).toRepresentation(); //<-- here
userResource.roles().clientLevel(clientId).add(Collections.singletonList(clientRole));
}
It returns me a HTTP 404 error. Digging deeper and it looks like that the .roles()
method failes. The User is created in my keycloak, just my role is not assigned. .roles()
:
@Path("/roles")
RolesResource roles();
Any idea how to fix this? Getting frustrated by now.