How to implement admin becoming another user temporarily?

女生的网名这么多〃 提交于 2019-12-11 17:27:15

问题


I have a traditional Rails 4 app with a User model and Sorcery for authentication. The User model has an 'admin' flag. What's the best way to implement the ability for admins to temporarily become another user (in order to see what the user sees to help debug a problem) and then pop back to being their original, admin-enabled user?


回答1:


here's a implementation:

http://robots.thoughtbot.com/how-to-masquerade-as-another-user-to-see-how-they-use-yo

I think this was what you were looking for




回答2:


I do not know about rails, but under Unix, your executable needs to be allowed to switch between user modes. That is done by setting the 's' bit on your executables and setting up the owner and/or group to what is required to do whatever you want the application to be capable of. (i.e. most often you use root as the owner and srwxr-xr-x as the permissions, which is 4755 as a mode number).

Once you have that in place, your application can use the function setuid(<uid>). If you use root, the <uid> would be 0 (zero).

Under Linux you have seteuid(), setfsuid(), and setreuid() as well.

To make sure you're doing the right thing, I suggest that you read the corresponding manual pages.




回答3:


I have no experience with this matter, but perhaps you can add a superuser flag to your User model. If you are a superuser you can adjust the admin flag. The only point of the superuser is just to be able to turn admin rights off or on. Now you can switch between being an user or an admin and see what the user sees. Once done you enable admin and you get your admin interface back.

This would work, but I don't know if it is the best solution for your use case. Just theorycrafting here. :)



来源:https://stackoverflow.com/questions/22726781/how-to-implement-admin-becoming-another-user-temporarily

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