Security has role vs is_granted

Viewed 1156

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?

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.

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.

Related