Symfony2: Reload user roles

Symfony2: Reload user roles

If you are not using FOSUserBundle for managing your user system, then you might have stumbled onto a problem of reloading user roles when you change them. Here is a possible solution.

Your UserInterface::equals() method might look something like this:

Now all you need to do is change it so it also checks the user roles:

And it should work!

Now whenever you change any user’s roles it will be effective immediately after the next page refresh instead of logout / login.