Symfony2:在数据库中存储用户、角色、角色层次结构和访问控制
我第一次使用 Symfony (2.x),对角色的定义、角色层次结构以及如何将它们分配给各个用户有一些疑问。
我有兴趣将角色和角色层次结构存储在数据库中(而不是 security.yml);但是,我找不到任何支持这一点的文档。这是可取的吗?
我对拥有一个可以添加新角色并定义角色层次结构的管理模块感兴趣;然而,让管理模块修改 security.yml 或其他一些配置文件似乎是一个坏主意。
这显然需要 ACL 也可以存储在数据库中。
- 有人有任何可能对此有所帮助的提示或文档吗?
- 就性能而言,这是一个坏主意吗?
我过去已经使用 Zend Framework 成功实现了这一点,并希望使用 Symfony2 也能做到同样的事情。
I've been working with Symfony (2.x) for the first time and I had some questions regarding the definition of roles, role hierarchy, and how they can be assigned to individual users.
I was interested in storing the roles and role hierarchy in a database (rather than security.yml); however, I cannot find any documentation supporting this. Is this advisable?
I was interested in having an admin module that can add new roles and define role hierarchies; however, having the admin module modify security.yml or some other config file seems like a bad idea.
This obviously would require that the ACLs can be stored in a database as well.
- Does anyone have any tips or documentation that might help with this?
- Is it a bad idea, performance wise?
I've been successful implementing this with Zend Framework in the past and was hoping to do the same with Symfony2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您可能想看看 FOSUserBundle
Perhaps you might want to have a look at FOSUserBundle
解决方案:
以下食谱条目是关于在数据库中存储/检索用户和角色的
“如何从数据库(实体提供者)加载安全用户”
http://symfony.com/doc/current/cookbook/security/entity_provider.html
长话短说,您的
role
和user
实体类必须实现 RoleInterface 和 用户界面 / AdvancedUserInterface 并且您必须对您的 <代码>安全.ymlThe solution:
The following cookbook entry is about storing/retrieving users and roles to/from the database
"How to load Security Users from the Database (the Entity Provider)"
http://symfony.com/doc/current/cookbook/security/entity_provider.html
To make the long story short, your
role
anduser
entity classes have to implement RoleInterface and UserInterface / AdvancedUserInterface and you have to make some changes to yoursecurity.yml
您需要将角色放入数据库中,并使用多对多关系进行映射。然后在角色上建立一些管理。我在 http://blog.jmoz 编写了如何更改用户以使用 m2m 角色.co.uk/symfony2-fosuserbundle-role-entities。我还没有了解角色层次结构,因此它仍然存储在配置中。
You would need to put the roles in the db, and map it using a many-to-many relation. Then build some admin on the roles. I wrote how to change the User to use m2m roles at http://blog.jmoz.co.uk/symfony2-fosuserbundle-role-entities. I haven't got as far as the role hierarchy so that is still stored in the config.