dragoninasia2014 2018-05-10 11:23
浏览 59

是否可以将当前防火墙的用户提供程序服务注入自定义服务?

I'm facing a good challenge in one of my projects.

I need to inject the User Provider defined for a firewall in a service of a third party bundle that I'm developing. I cannot define it explicitly in my service, because I want to achieve that, when the service is called from a different firewall or the user changes the provider in security.yaml, my service adapts to use the right provider.

What I've been able to accomplish is to get just the name of the provider by injecting the RequestStack and the FirewallMap and getting the FirewallConfig using the current request, but nothing more, just the name.

I wonder if there's a way of doing this. There's nothing in the docs with regards to this. But I'm sure there must be a way, since the authentication listeners in Security Bundle do the same.

I'm reading your clever responses! :)

  • 写回答

1条回答 默认 最新

  • douxian6260 2018-05-11 10:55
    关注

    Have you tried looking into the FirewallConfig class? It's not documented very well, but it exists, and can be accessed via $firewallMap->GetFirewallConfig($request). Every information about the firewall is stored in this object, as well as the provider ($firewallConfig->getProvider()).

    If you have been able to inject the FirewallMap config, I think you can also pass the current Request object as a parameter to obtain the FirewallConfig:

    public class YourService()
    {
        ...
        public function YourMethod(Request $request)
        {
            // Your FirewallMap injection
            ...
    
            $firewallConfig = $firewallMap->getFirewallConfig($request);
    
            // Proceed with $firewallConfig information
        }
    }
    

    More on the FirewallConfig class here.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程