You are here

protected function AccessTokenAccessControlHandler::checkAccess in Simple OAuth (OAuth2) & OpenID Connect 8

Same name and namespace in other branches
  1. 8.2 src/AccessTokenAccessControlHandler.php \Drupal\simple_oauth\AccessTokenAccessControlHandler::checkAccess()

Performs access checks.

This method is supposed to be overwritten by extending classes that do their own custom access checking.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.

string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.

\Drupal\Core\Session\AccountInterface $account: The user for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkAccess

File

src/AccessTokenAccessControlHandler.php, line 19

Class

AccessTokenAccessControlHandler
Access controller for the Access Token entity.

Namespace

Drupal\simple_oauth

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  // Permissions only apply to own entities.
  if ($account
    ->id() != $entity
    ->get('auth_user_id')->target_id) {
    return AccessResult::forbidden();
  }
  switch ($operation) {
    case 'view':
      return AccessResult::allowedIfHasPermission($account, 'view own access token entities');
    case 'update':
      return AccessResult::allowedIfHasPermission($account, 'edit own access token entities');
    case 'delete':
      return AccessResult::allowedIfHasPermission($account, 'delete own access token entities');
  }
  return AccessResult::allowed();
}