vendor/sulu/sulu/src/Sulu/Component/Security/Authorization/AbstractSecurityChecker.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Security\Authorization;
  11. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  12. /**
  13.  * Implements an abstraction for the SecurityCheckerInterface, which needs the subclass to implement the
  14.  * hasPermission method. This method will be called for the checkPermission method, which throws an exception,
  15.  * if permission is not granted.
  16.  */
  17. abstract class AbstractSecurityChecker implements SecurityCheckerInterface
  18. {
  19.     public function checkPermission($subject$permission)
  20.     {
  21.         if (!$this->hasPermission($subject$permission)) {
  22.             if ($subject instanceof SecurityCondition) {
  23.                 $message \sprintf(
  24.                     'Permission "%s" in localization "%s" for context "%s" and object with id "%s" and type "%s" not granted',
  25.                     $permission,
  26.                     $subject->getLocale(),
  27.                     $subject->getSecurityContext(),
  28.                     $subject->getObjectId(),
  29.                     $subject->getObjectType()
  30.                 );
  31.             } else {
  32.                 $message \sprintf('Permission "%s" in security context "%s" not granted'$permission$subject);
  33.             }
  34.             throw new AccessDeniedException($message);
  35.         }
  36.         return true;
  37.     }
  38.     abstract public function hasPermission($subject$permission);
  39. }