File tree Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -599,8 +599,42 @@ anything else within your firewall in the :ref:`access control
599
599
600
600
$ composer require --dev symfony/profiler-pack
601
601
602
- Now that we understand our firewall, the next step is to create a way for your
603
- users to authenticate!
602
+ Fetching the Firewall Configuration for a Request
603
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
604
+
605
+ If you need to get the configuration of the firewall that matched a given request,
606
+ use the :class: `Symfony\\ Bundle\\ SecurityBundle\\ Security\\ Security ` service::
607
+
608
+ // src/Service/ExampleService.php
609
+ // ...
610
+
611
+ use Symfony\Bundle\SecurityBundle\Security\Security;
612
+ use Symfony\Component\HttpFoundation\RequestStack;
613
+
614
+ class ExampleService
615
+ {
616
+ private Security $security;
617
+
618
+ public function __construct(Security $security, RequestStack $requestStack)
619
+ {
620
+ $this->requestStack = $requestStack;
621
+ // Avoid calling getFirewallConfig() in the constructor: auth may not
622
+ // be complete yet. Instead, store the entire Security object.
623
+ $this->security = $security;
624
+ }
625
+
626
+ public function someMethod()
627
+ {
628
+ $request = $this->requestStack->getCurrentRequest();
629
+ $firewallName = $this->security->getFirewallConfig($request)?->getName();
630
+
631
+ // ...
632
+ }
633
+ }
634
+
635
+ .. versionadded :: 6.2
636
+
637
+ The ``getFirewallConfig() `` method was introduced in Symfony 6.2.
604
638
605
639
.. _security-authenticators :
606
640
You can’t perform that action at this time.
0 commit comments