File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,25 @@ with ``ROLE_SUPER_ADMIN``::
256256        } 
257257    } 
258258
259+ .. caution ::
260+ 
261+     In the previous example, avoid using the following code to check if a role
262+     is granted permission::
263+ 
264+         // DON'T DO THIS 
265+         use Symfony\Component\Security\Core\Security; 
266+         // ... 
267+ 
268+         if ($this->security->isGranted('ROLE_SUPER_ADMIN')) { 
269+             // ... 
270+         } 
271+ 
272+         The ``Security::isGranted()`` method inside a voter has a significant 
273+         drawback: it does not guarantee that the checks are performed on the same 
274+         token as the one in your voter. The token in the token storage might have 
275+         changed or could change in the meantime. Always use the ``AccessDecisionManager`` 
276+         instead. 
277+ 
259278If you're using the :ref: `default services.yaml configuration  <service-container-services-load-example >`,
260279you're done! Symfony will automatically pass the ``security.helper ``
261280service when instantiating your voter (thanks to autowiring).
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments