symfony在不同的主机上模拟 [英] symfony impersonate across different hosts

查看:55
本文介绍了symfony在不同的主机上模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Symfony中模拟不同的用户,但与其他示例不同,例如

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

因此,通过这种设置,当我尝试模拟用户时,它将保留在管理站点中,并且当然,被正确选择的客户端无法在管理端进行身份验证.当然,当移至客户端时,那里不存在auth会话.

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.

我试图让系统的主机知道在哪里冒充" in".

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

我可能不得不陷入 http://中提到的侦听器symfony.com/doc/current/security/impersonating_user.html#events ,但我没有找到有关如何执行此操作的详细信息.

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.

推荐答案

chainUserProvider允许您将一个或多个用户提供程序添加在一起,以便可以从这些多个来源获取用户.请注意,将提供程序添加到ChainUserProvider的顺序很重要:一旦找到一个用户,即使该用户的凭据失败,它也会对该用户进行检查.

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%

这篇关于symfony在不同的主机上模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆