[keycloak-user] programatically create user gives 400 bad request

Dirk Franssen dirk.franssen at gmail.com
Mon Jan 11 20:08:11 EST 2016


Hi,

I have a standard keycloak 1.7.0-Final and a separate jax-rs service (both
in docker) to create a simple test-user programatically with hardcoded
params:

@Path("users")
@Stateless
public class UsersResource {

    @POST
    public Response createTestUser() {
        Keycloak kc = Keycloak.getInstance(
                "http://192.168.99.100:8180/auth",
                "master",
                "admin", "password",
                "security-admin-console");

        CredentialRepresentation credential = new
CredentialRepresentation();
        credential.setType(CredentialRepresentation.PASSWORD);
        credential.setValue("test123");
        credential.setTemporary(false); /
        UserRepresentation user = new UserRepresentation();
        user.setUsername("testuser");
        user.setFirstName("Test");
        user.setLastName("User");
        user.setCredentials(Arrays.asList(credential));
        user.setEnabled(true);
        user.setRealmRoles(Arrays.asList("admin"));
        Response result = kc.realm("master").users().create(user);
        return result;
    }
}

But calling the JAX-RS endpoint returns in a delegated 400 Bad request. The
KC log states only:

00:40:23,436 WARN  [org.keycloak.events] (default task-9) type=LOGIN_ERROR,
realmId=master, clientId=security-admin-console, userId=null,
ipAddress=172.17.0.1, error=not_allowed, grant_type=password,
auth_method=oauth_credentials, client_auth_method=client-secret

Any ideas?

Kind regards,

Dirk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160112/85733c78/attachment-0001.html 


More information about the keycloak-user mailing list