From f807b5fc15588d9590fd134917f83f56ac3c203c Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Sat, 10 Oct 2020 17:10:29 +0200 Subject: [PATCH] Add error message when using LoginLinkHandler outside a firewall --- .../LoginLink/FirewallAwareLoginLinkHandler.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/LoginLink/FirewallAwareLoginLinkHandler.php b/src/Symfony/Bundle/SecurityBundle/LoginLink/FirewallAwareLoginLinkHandler.php index eaa52058f2..052dcdcf62 100644 --- a/src/Symfony/Bundle/SecurityBundle/LoginLink/FirewallAwareLoginLinkHandler.php +++ b/src/Symfony/Bundle/SecurityBundle/LoginLink/FirewallAwareLoginLinkHandler.php @@ -53,9 +53,14 @@ class FirewallAwareLoginLinkHandler implements LoginLinkHandlerInterface throw new \LogicException('Cannot determine the correct LoginLinkHandler to use: there is no active Request and so, the firewall cannot be determined. Try using the specific login link handler service.'); } - $firewallName = $this->firewallMap->getFirewallConfig($request)->getName(); + $firewall = $this->firewallMap->getFirewallConfig($request); + if (!$firewall) { + throw new \LogicException('No login link handler found as the current route is not covered by a firewall.'); + } + + $firewallName = $firewall->getName(); if (!$this->loginLinkHandlerLocator->has($firewallName)) { - throw new \InvalidArgumentException(sprintf('No login link handler found. Did you add a login_link key under your "%s" firewall?', $firewallName)); + throw new \LogicException(sprintf('No login link handler found. Did you add a login_link key under your "%s" firewall?', $firewallName)); } return $this->loginLinkHandlerLocator->get($firewallName);