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.

createRole #

Create a new role in Kuzzle.

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


createRole(id, content, [options], callback) #

Arguments Type Description
id string Unique role identifier
content JSON Object A plain JSON object representing the role
options string (Optional) Optional arguments
callback function Callback handling the response

Options #

Filter Type Description Default
replaceIfExist boolean If the same role already exists: throw an error if sets to false. Replace the existing role otherwise false
queuable boolean Make this request queuable or not true
refresh string If set to wait_for, Kuzzle will wait the persistence layer to finish indexing (available with Elasticsearch 5.x and above) undefined

Callback Response #

Returns a Role object.

Usage #

Copied to clipboard!
JSONObject roleDefinition = new JSONObject()
  .put("controllers", new JSONObject()
    .put("*", new JSONObject()
      .put("actions", new JSONObject()
        .put("*", true)
      )
    )
  )
);
Options opts = new Options().setReplaceIfExist(true);
kuzzle
  .security
  .createRole("myrole", roleDefinition, opts, new ResponseListener<Role>() {
    @Override
    public void onSuccess(Role role) {
      // the result is an instantiated Role object
    }
    @Override
    public void onError(JSONObject error) {
    }
  })