1

I'm trying to impersonate different users in Symfony, but different that other examples like Symfony impersonation - separate firewalls and separate user providers, in my case is not only the provider that's different, but the host.

firewalls:
   admin:
        pattern: ^/
        host: "%host_admin%"
        provider: admin
[...]
      switch_user:
        role: ROLE_ADMIN
        provider: client
        #host: "%host_public%" <-- tried this.. does not work
        context: cmb_context

   client:
        pattern: ^/
        host: "%host_public%"
        provider: client
[...]
      switch_user:
        role: ROLE_ADMIN
        provider: client
        context: cmb_context

So, with this set-up when i try to impersonate a user, it remains in the admin site and of course the client, that's been picked up correctly, can not authenticate in the admin side. When moving to the client, of course, the auth session is not present there.

I tried putting the host for the system to know where to impersonate "in" with no luck.

I might have to fall down to the listener mentioned in http://symfony.com/doc/current/security/impersonating_user.html#events but i have not found details on how to do that.

Any ideas? Thanks in advance.

rrubiorr81
  • 285
  • 1
  • 5
  • 15

1 Answers1

0

The chainUserProvider allows you to add one or more user providers together so you can fetch users from these multiple sources. Note that the order in which you add the providers to the ChainUserProvider will matter: as soon as a user has been found, it will check against that user, even if the credentials of that user fails.

parameters:
    chain_providers: "mydatabase1,mydatabase2"

security:
    providers:
        mydatabase1:
            entity:
                class: My\UserBundle\Entity\Admin
                property: username

        mydatabase2:
            entity:
                class: My\UserBundle\Entity\Customer
                property: username

        my_chain:
            chain:
                providers: %chain_providers%
Mohamed Ben HEnda
  • 2,686
  • 1
  • 30
  • 44
  • thanks @Mohamed for you answer. The problem i have is not getting the entity data to be pulled in my firewall, i can even see the right username being loaded in my symfony dev-bar on the bottom of the page (one of the other public entities); but be able to log as this same entity in a different host (initially i'm in the admin host and i want to log as client in the client host)... – rrubiorr81 Dec 15 '16 at 15:49