[英]How to store user roles in separate table in Symfony2?
I have following doctrine entities in my Symfony2.8 project. 我在Symfony2.8项目中有以下doctrine实体。
User 用户
id
email
username
password
Organization 组织
id
name
subdomain
UserOrganization UserOrganization
organization_id
user_id
roles
I need to load user roles from UserOrganization table, So how can I override Symfony authentication flow to load user roles from "UserOrganization" entity. 我需要从UserOrganization表加载用户角色,那么如何覆盖Symfony身份验证流以从“UserOrganization”实体加载用户角色。
NOTE: 注意:
xyz.mydomain.com here xyz is organization. xyz.mydomain.com这里xyz是组织。
so while user tries to login from xyz subdomain Symfony2 must read roles for the user from xyz organization's record in UserOrganization table 因此,当用户尝试从xyz子域登录时,Symfony2必须从UserOrganization表中的xyz组织记录中读取用户的角色
You should implement your own Custom UserProvider 您应该实现自己的自定义UserProvider
in which you can Inject the UserOrganization
repository and query that repository on the implemented provider. 您可以在其中注入
UserOrganization
存储库并在已实现的提供程序上查询该存储库。
Remember that your UserOrganization
Entity class must implement UserInterface in order to be used during the security flow. 请记住,您的
UserOrganization
Entity类必须实现UserInterface才能在安全流程中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.