Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security has role vs is_granted

Tags:

symfony

Could some explain to me the difference between : @Security("has_role("ROLE_ADMIN")") and @Security("is_granted("ROLE_ADMIN")") and which one is more recommended?

like image 570
Aya Avatar asked Dec 23 '20 14:12

Aya


2 Answers

They do the same job in that case, but the has_role() function in security expressions is deprecated since Symfony 4.2, so we should use is_granted() instead.

like image 76
famas23 Avatar answered Oct 17 '22 22:10

famas23


I think that has_role() checks if the user already has the role. On the other hand, is_granted() runs the Voters to check if there is a role to be added to the existing roles.

like image 1
Yassine Younes Avatar answered Oct 17 '22 22:10

Yassine Younes