I am very new at Symfony2, so please bear with me. I am working on creating a web application where there will be two websites/parent bundles sharing a common bundle. Part of the bundle is my User entity model. With these websites, there are subscriptions to be purchased so the user can access the program part of these websites.
I am thinking that the best is to use the Roles authorization mechanism. I am running into a problem with that. The problem is that I cannot access variables/services (meaning, my website service, which contains information about the current website session) outside of that entity – and that does make sense. Is there a way to take the standard User (class User implements AdvancedUserInterface, \Serializable) entity that I am using for authentication, and turn it into a service? But that seems to present problems because I am using a custom repository for the User class which returns a User class.
So, how can I get external information injected into a User entity model? – I think that is the summary of what I am asking.
Edit:
This is my class definition for the user class:
class User implements AdvancedUserInterface, \Serializable
Here is my security.yml for the website:
providers:
database:
entity: { class: WebsiteCommonBundle:User }
I would like to implement the getRoles() function to provide the current roles that the user is a part of. The challenge is that this is dependent on certain criteria to be met (which is different for each website). This information comes from a Symfony service, and it is there, I just don’t know how to get that information pushed into the entity.
Just having
Usersisn’t enough for assigning roles/access to the web application. To handle that, you’ll want to implement aUserProvideras well. The docs give a pretty good start on the topic.