<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kunstmaan\AdminBundle\Helper\Security\Acl\Voter;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Acl\Model\AclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
use Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface;
use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
use Symfony\Component\Security\Acl\Voter\AclVoter as BaseAclVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* This voter can be used as a base class for implementing your own permissions.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class AclVoter extends BaseAclVoter
{
/** @var bool */
private $permissionsEnabled;
public function __construct(AclProviderInterface $aclProvider, ObjectIdentityRetrievalStrategyInterface $oidRetrievalStrategy, SecurityIdentityRetrievalStrategyInterface $sidRetrievalStrategy, PermissionMapInterface $permissionMap, LoggerInterface $logger = null, $allowIfObjectIdentityUnavailable = true, $permissionsEnabled = true)
{
parent::__construct($aclProvider, $oidRetrievalStrategy, $sidRetrievalStrategy, $permissionMap, $logger, $allowIfObjectIdentityUnavailable);
$this->permissionsEnabled = $permissionsEnabled;
}
public function vote(TokenInterface $token, $object, array $attributes)
{
$attributeIsSupported = false;
foreach ($attributes as $attribute) {
if ($this->supportsAttribute($attribute)) {
$attributeIsSupported = true;
break;
}
}
if (!$this->permissionsEnabled && $attributeIsSupported) {
return self::ACCESS_GRANTED;
}
if (!$this->permissionsEnabled) {
return self::ACCESS_ABSTAIN;
}
return parent::vote($token, $object, $attributes);
}
}