0

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 Answers1

0

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.

Leon Willens
  • 356
  • 1
  • 16
  • Thanks for your help Leon. I'm sorry that I wasn't clear enough and I'm wasting your time. This is what I meant that I was able to just get the name of the provider just injecting the `RequestStack` and the `FirewallMap`. In firewall map I call `$map->getFirewallConfig($request)->getProvider()`. But that only returns the name of the provider that has been configured. Maybe there's another service to resolve the provider name, but I can't find anything. Kinda trapped here. – Matías Navarro Carter May 11 '18 at 11:22
  • Can you elaborate what exactly you need from the user provider? – Leon Willens May 12 '18 at 10:10
  • To load a user by the username. – Matías Navarro Carter May 12 '18 at 13:32