0

Using Guard Auth, Symfony 3.4, FOSuser Bundle.

My registered user, can create subaccount for different tasks. If my user logout, and login to that subaccount (routes from Fuser bundle) All works as expected. Account have needed priveledges, all works fine.

I would like to create for my logged user - a switcher for all his subaccounts. (Each subb account have his owner id, and acc_type field)

how create proper controller (inherits proper interfaces, etc), form, and use builded in FOSuser services to reload / switch user to his other account?

in render controller view (fill hidden field as his password, add "submit" btn to initiate login)

zoore
  • 293
  • 5
  • 13

1 Answers1

1

I believe you can accomplish the specified behavior with impersonating user feature.

You should enable such option in your config file first

# config/packages/security.yaml
security:
    # ...

    firewalls:
        main:
            # ...
            switch_user: true

And also please note that the feature is only available to users with a special role called ROLE_ALLOWED_TO_SWITCH. Use role_hierarchy to give this role to the users that need it.

Majesty
  • 2,097
  • 5
  • 24
  • 55
  • hi Lunin, this changing ROLE, creating security issues, I'm creating diff accounts, for purpose, it's not a matter of permisions, it'sa matter of how behave with user subaccounts – zoore Jan 04 '19 at 09:45
  • this is what impersonating feature about, but you should specify manually which roles are allowed to perform the switch, this is the best solution for you if I understand your problem correctly, just read the documentation carefuly – Majesty Jan 04 '19 at 13:18
  • I have readed it, in my case all users in my webservice should have this role enabled, that's why this feature is useless. – zoore Jan 06 '19 at 14:01
  • can't understand what's wrong about it? if you have some security concerns then you should create your own solution according to your needs, no other way from the box I know, let us know when you come up with something, I am also curious:) – Majesty Jan 06 '19 at 16:11