FOSUserBundle/Symfony2: Force logout of a user given a user (not the currently logged in user)

人盡茶涼 提交于 2019-12-12 09:43:31

问题


Whenever I edit a user's role, the user needs to logout and log back in to see the changes. There's no problem when promoting a user as they just won't see the extra permissions until signing in again. However, when a demotion was to occur, a user will still keep its existing role which impose security risks. Imagine revoking admin user on a rogue employee, and still have them be able to do anything (eg. sabotaging the system) until they log out!

Is it possible to invalidate all sessions or tokens that are related to a specific user? If there is another way to dynamically update the roles of a user without logging them out, I would love to hear it!

Just to make it clear, I'm not trying to invalidate the currently logged in user's session/token.

Thanks in advance!


回答1:


Symfony stores serialized token object under _security_match_firewall_name key in session. You can unserialize it, filter role and then save it again. For reading/saving session values you can use PdoSessionStorage. You may have to create an extra table for tracking users session.



来源:https://stackoverflow.com/questions/9630032/fosuserbundle-symfony2-force-logout-of-a-user-given-a-user-not-the-currently-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!