isActionAllowed

kuzzle.security.getMyRights((err, rights) => {
    if (!err) {
        // returns either "allowed", "denied" or "conditional"
        var allowed = kuzzle.security.isActionAllowed(rights, 'read', 'get', 'index1', 'collection1');
    }
});
kuzzle.security.getMyRights(new ResponseListener<JSONObject[]>() {
    @Override
    public void onSuccess(JSONObject[] rights) {
        // Policies is an enum with the following properties:
        // allowed, denied, conditional
        Policies authorization = kuzzle.security.isActionAllowed(rights, "read", "get", "index1", "collection1");
    }

    @Override
    public void onError(JSONObject error) {
     // ...
    }
});
<?php

use \Kuzzle\Kuzzle;
use \Kuzzle\Security\Security;

$kuzzle = new Kuzzle('localhost');

try {
  $rights = $kuzzle->security()->getMyRights();

  switch ($kuzzle->security()->isActionAllowed($rights, 'read', 'get', 'index1', 'collection1')) {
    case Security::ACTION_ALLOWED:
      // code...
      break;
    case Security::ACTION_DENIED:
      // code...
      break;
    case Security::ACTION_CONDITIONAL:
      // code...
      break;
  }
}
catch (ErrorException $e) {

}

Tells whether an action is allowed, denied or conditional based on the rights provided as the first argument:

  • allowed is returned when an action is authorized without condition
  • conditional is returned when the authorization depends on a closure
  • denied is returned when the action is forbidden

An action is defined as a couple of action and controller (mandatory), plus an index and a collection(optional).


isActionAllowed(rights, controller, action, index, collection)

ArgumentsTypeDescription
rightsJSON arrayRights list
controllerStringThe controller
actionStringThe action
indexStringThe index
collectionStringThe collection

Return value

Returns either allowed, denied or conditional.