Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit 78f5832

Browse files
committed
Compatibility with Symfony 5.2
1 parent 626772d commit 78f5832

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Security/Authorization/TwoFactorAccessDecider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\HttpFoundation\Request;
88
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
99
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
10+
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
1011
use Symfony\Component\Security\Http\AccessMapInterface;
1112
use Symfony\Component\Security\Http\Firewall\AccessListener;
1213
use Symfony\Component\Security\Http\HttpUtils;
@@ -50,10 +51,17 @@ public function isAccessible(Request $request, TokenInterface $token): bool
5051
{
5152
// Let routes pass, e.g. if a route needs to be callable during two-factor authentication
5253
list($attributes) = $this->accessMap->getPatterns($request);
54+
55+
// Compatibility for Symfony 5.1
5356
if (\defined(AccessListener::class.'::PUBLIC_ACCESS') && [AccessListener::PUBLIC_ACCESS] === $attributes) {
5457
return true;
5558
}
5659

60+
// Compatibility for Symfony 5.2+
61+
if (\defined(AuthenticatedVoter::class.'::PUBLIC_ACCESS') && [AuthenticatedVoter::PUBLIC_ACCESS] === $attributes) {
62+
return true;
63+
}
64+
5765
if (null !== $attributes && $this->accessDecisionManager->decide($token, $attributes, $request)) {
5866
return true;
5967
}

Tests/Security/Authorization/TwoFactorAccessDeciderTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\HttpFoundation\Request;
1212
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1313
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
14+
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
1415
use Symfony\Component\Security\Http\AccessMapInterface;
1516
use Symfony\Component\Security\Http\Firewall\AccessListener;
1617
use Symfony\Component\Security\Http\HttpUtils;
@@ -137,8 +138,25 @@ public function isAccessible_pathAccessGranted_returnTrue(): void
137138
public function isAccessible_isPublic_returnTrue(): void
138139
{
139140
$this->requireAtLeastSymfony5_1();
141+
$publicAccess = null;
140142

141-
$this->stubAccessMapReturnsAttributes([AccessListener::PUBLIC_ACCESS]);
143+
// Compatibility with Symfony 5.1
144+
if (\defined(AccessListener::class.'::PUBLIC_ACCESS')) {
145+
$publicAccess = AccessListener::PUBLIC_ACCESS;
146+
}
147+
148+
// Compatibility for Symfony 5.2+
149+
if (\defined(AuthenticatedVoter::class.'::PUBLIC_ACCESS')) {
150+
$publicAccess = AuthenticatedVoter::PUBLIC_ACCESS;
151+
}
152+
153+
if (null === $publicAccess) {
154+
$this->fail('Could not find PUBLIC_ACCESS constant.');
155+
156+
return;
157+
}
158+
159+
$this->stubAccessMapReturnsAttributes([$publicAccess]);
142160
$this->whenRequestBaseUrl('');
143161
$this->whenGeneratedLogoutPath(self::LOGOUT_PATH);
144162
$this->whenPathAccess(false);

0 commit comments

Comments
 (0)