Force reauthentication after user permissions have been changed

不羁岁月 提交于 2019-12-03 12:42:57

Make your user class implement Symfony\Component\Security\Core\User\EquatableInterface.

If you return false from the isEqualTo() method, the user will be reauthenticated. Use that method to compare only those properties that when changed should force reauthentication — roles in your case.

JamesHalsall

You can get around this issue by following an approach similar to what I did:

  1. When user logs in, store all permissions in session along with a checksum of those permissions.
  2. Store the same checksum in a database, or on disk, against that user ID
  3. Whenever the user makes a request, verify that the checksum on disk matches the one in session for that user. If it is different, reload the permissions into the user's session
  4. When you change the permissions, update the checksum in the database (or on disk) that is stored against that user. This will trigger a resync on their next request.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!