symfony impersonate across different hosts

余生长醉 提交于 2019-12-12 01:44:45

问题


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.


回答1:


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%


来源:https://stackoverflow.com/questions/41153988/symfony-impersonate-across-different-hosts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!