@@ -195,7 +195,7 @@ elevated user such as an administrator.
195
195
196
196
First, create the voter class::
197
197
198
- namespace AppBundle \Security\Voter;
198
+ namespace App \Security\Voter;
199
199
200
200
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
201
201
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
@@ -227,7 +227,7 @@ First, create the voter class::
227
227
228
228
if (in_array('ROLE_CUSTOMER', $subject->getRoles())
229
229
&& $this->hasSwitchToCustomerRole($token)) {
230
- return self::ACCESS_GRANTED ;
230
+ return true ;
231
231
}
232
232
233
233
return false;
@@ -340,6 +340,7 @@ the voter as a service:
340
340
// config/services.php
341
341
use App\Security\Voter\SwitchToCustomerVoter;
342
342
use Symfony\Component\DependencyInjection\Definition;
343
+ use Symfony\Component\DependencyInjection\Reference;
343
344
344
345
// Same as before
345
346
$definition = new Definition();
@@ -354,7 +355,7 @@ the voter as a service:
354
355
355
356
// Explicitly configure the service
356
357
$container->getDefinition(SwitchToCustomerVoter::class)
357
- ->setArgument('$roleHierarchy', '@ security.role_hierarchy');
358
+ ->setArgument('$roleHierarchy', new Reference(' security.role_hierarchy') );
358
359
359
360
Now a user who has the ``ROLE_SWITCH_TO_CUSTOMER `` role can switch to a user who explicitly has the
360
361
``ROLE_CUSTOMER `` role, but not other users.
0 commit comments