You are here

protected function Handler::checkAccess in JSON-RPC 2.x

Same name and namespace in other branches
  1. 8 src/Handler.php \Drupal\jsonrpc\Handler::checkAccess()

Check execution access.

Parameters

\Drupal\jsonrpc\MethodInterface $method: The method for which to check access.

Throws

\Drupal\jsonrpc\Exception\JsonRpcException

1 call to Handler::checkAccess()
Handler::doExecution in src/Handler.php
Gets an anonymous function which executes the RPC method.

File

src/Handler.php, line 217

Class

Handler
Manages all the JSON-RPC business logic.

Namespace

Drupal\jsonrpc

Code

protected function checkAccess(MethodInterface $method) {

  // TODO: Add cacheability metadata here.

  /* @var \Drupal\jsonrpc\MethodInterface $method_definition */
  $access_result = $method
    ->access('execute', NULL, TRUE);
  if (!$access_result
    ->isAllowed()) {
    $reason = 'Access Denied';
    if ($access_result instanceof AccessResultReasonInterface && ($detail = $access_result
      ->getReason())) {
      $reason .= ': ' . $detail;
    }
    throw JsonRpcException::fromError(Error::invalidRequest($reason, $access_result));
  }
}