-1

I have an application where the Symfony Security User model (called Account) will just contain login information (username, password). The rest of the user will be stored in another model (called User). There will be a one to many relation between Account and User and the purpose of this is to be able to have multiple Users, for different projects, but have the same login for them.

So, my problem with this is that I want to use the role system in Symfony, but I want the User model to have roles, and not the Account model. I am not really sure how this can be solved, since the UserInterface is the Account model and not the User model.

Does Symfony support this or do I have to roll my own implementation of roles for this system?

rablentain
  • 6,641
  • 13
  • 50
  • 91
  • Your terminology is a bit confusing but assuming you know which User you want to use when an Account logs in then have a custom UserProvider load the Account and the User and then transfer the User roles to the Account object. At which point the security system will be happy. – Cerad Nov 16 '17 at 21:01

1 Answers1

0

You can just fetch the roles from the account model:

//Account
public function getRoles()
{
    return $this->getUser()->getRoles();
}

Using the association you get the roles that way, but you still have the method on the Account level.

Chase
  • 9,289
  • 5
  • 51
  • 77
  • Ok! Sounds promising. Not sure though, the roles should be different for different User objects even though those are associated with the same Account object, does that work? – rablentain Nov 16 '17 at 20:28