SDK
SDK Java v2.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

createUser #

Create a new user in Kuzzle.

There is a small delay between user creation and its availability in our search layer (usually a couple of seconds).
That means that a user that was just created might not be returned immediately by the searchUsers function.


createUser(id, user, [options], [callback]) #

ArgumentsTypeDescription
idstringUnique user identifier
userJSON ObjectA plain JSON object representing the user (see below)
optionsstring(Optional) Optional arguments
callbackfunctionCallback handling the response
refreshstringIf set to wait_for, Kuzzle will wait the persistence layer to finish indexing (available with Elasticsearch 5.x and above)

The user object to provide must have the following properties:

  • content (JSON object): user global properties
    • This object must contain a profileIds properties, an array of strings listing the security profiles to be attached to the new user
    • Any other property will be copied as additional global user information
  • credentials (JSON object): a description of how the new user can identify themselves on Kuzzle
    • Any number of credentials can be added, each one being an object with name equal to the authentication strategy used to authenticate the user, and with the login data as content.
    • If this object is left empty, the user will be created in Kuzzle but the will not be able to login.

Options #

FilterTypeDescriptionDefault
queuablebooleanMake this request queuable or nottrue

Callback Response #

Returns a User object.

Usage #

JSONObject content = new JSONObject()
  // A "profileIds" field is required to bind a user to existing profiles
  .put("profileIds", new JSONArray()
    .put("admin")
  )
  // You can also set custom fields to your user
  .put("firstname", "John")
  .put("lastname", "Doe");
JSONObject newUser = new JSONObject().put("content", content);
JSONObject credentials = new JSONObject()
  // Authentication strategy to use
  .put("local", new JSONObject()
    // The necessary information to provide vary,
    // depending on the chosen authentication strategy
    .put("password", "secret password")
    .put("username", "jdoe")
  );
newUser.put("credentials", credentials);
Options opts = new Options();
kuzzle
  .security
  .createUser("myNewUser", newUser, opts, new ResponseListener<User>() {
    @Override
    public void onSuccess(User user) {
    }
    @Override
    public void onError(JSONObject error) {
    }
  });