bundles/OAuth2Bundle/Security/Authorization/Voter/AccessTokenVoter.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * AccessTokenVoter.php File.
  5. * This file is part of the Payment.net Project.
  6. *
  7. * PHP version 5
  8. *
  9. * @category Application
  10. * @package Bdm\BackofficeBundle\Security\Authorization\Voter
  11. * @author Alexandr Bakurin <abakurin@bdmultimedia.fr>
  12. * @link http://www.payment.net/
  13. *
  14. * FEATURES :
  15. * ==========
  16. *
  17. * TODO-LIST :
  18. * ===========
  19. *
  20. * HISTORY :
  21. * =========
  22. * 20151021 - Alexandr Bakurin
  23. */
  24. namespace Bdm\OAuth2Bundle\Security\Authorization\Voter;
  25. use Bdm\OAuth2Bundle\Entity\AccessToken;
  26. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  27. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  28. use Symfony\Component\Security\Core\User\UserInterface;
  29. /**
  30. * AccessTokenVoter
  31. */
  32. class AccessTokenVoter extends Voter
  33. {
  34. const DELETE = 'DELETE';
  35. /**
  36. * @param string $sAttribute attribute
  37. * @param mixed $oSubject subject
  38. * @return bool
  39. */
  40. public function supports($sAttribute, $oSubject)
  41. {
  42. if ($sAttribute !== self::DELETE) {
  43. return false;
  44. }
  45. if ($oSubject instanceof AccessToken) {
  46. return true;
  47. }
  48. return false;
  49. }
  50. /**
  51. * Check if has access
  52. *
  53. * @param string $aAttr attr
  54. * @param object $mEntity entity
  55. * @param null $oUser user
  56. *
  57. * @return bool
  58. */
  59. /**
  60. * @param string $sAttribute attribute
  61. * @param object $mEntity application
  62. * @param TokenInterface $oToken token
  63. * @return bool
  64. */
  65. protected function voteOnAttribute($sAttribute, $mEntity, TokenInterface $oToken)
  66. {
  67. $oUser = $oToken->getUser();
  68. if (!$oUser instanceof UserInterface) {
  69. return false;
  70. }
  71. if ($mEntity->getClient()->getMerchant() === $oUser) {
  72. return true;
  73. }
  74. return false;
  75. }
  76. }