Symfony2:在数据库中存储用户,角色,角色层次结构和访问控制 [英] Symfony2: Storing users, roles, role hierarchy, and access controls in database
问题描述
我第一次与Symfony(2.x)一起工作,我对角色的定义,角色层次结构以及如何将其分配给各个用户有一些疑问。
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.
我有兴趣将角色和角色层次结构存储在数据库中(而不是security.yml);但是,我找不到任何支持此操作的文档。
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?
我对拥有一个可以添加新角色并定义角色层次结构的管理模块感兴趣;但是,让管理模块修改security.yml或其他一些配置文件似乎是个坏主意。
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.
这显然要求ACL可以存储为
This obviously would require that the ACLs can be stored in a database as well.
- 有人有任何提示或文档可能对此有所帮助吗?
- 这是个坏主意吗,性能明智的选择吗?
过去,我已经使用Zend Framework成功实现了这一目标,并希望对Symfony2做到这一点。
I've been successful implementing this with Zend Framework in the past and was hoping to do the same with Symfony2.
推荐答案
解决方案:
以下食谱条目是关于将用户和角色存储到数据库$ b / b,以及从数据库
检索如何从数据库(实体提供者)加载安全用户。
http://symfony.com/doc/current/cookbook/security/entity_provider.html
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
长话短说,您的角色
和 user
实体类必须实现 RoleInterface 和 UserInterface / AdvancedUserInterface ,您必须对 security.yml $ c $进行一些更改c>
To make the long story short, your role
and user
entity classes have to implement RoleInterface and UserInterface / AdvancedUserInterface and you have to make some changes to your security.yml
这篇关于Symfony2:在数据库中存储用户,角色,角色层次结构和访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!