Skip to content

Commit cefb384

Browse files
Merge branch '5.4' into 6.0
* 5.4: (22 commits) fix cs Update validators.lv.xlf Fix API gateway service name Improve recommendation message for "composer req" Fix CS in composer.json [DependencyInjection] fix preloading Update validators.uz.xlf AddMake ExpressionVoter Cacheable Add framework config for DBAL cache adapter [ExpressionLanguage] Fix LexerTest number types [Process] intersect with getenv() to populate default envs Improve CI script a bit Fix deprecation message placeholders [Cache] Fix calculate ttl in couchbase sdk 3.0 Fix Loco Provider [Cache] fix dbindex Redis Fix typos in a test message [Cache] fix releasing not acquired locks [DependencyInjection] fix creating 2nd container instances Never rely on dynamic properties ...
2 parents becd745 + b6ff133 commit cefb384

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

Authorization/Voter/ExpressionVoter.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @author Fabien Potencier <fabien@symfony.com>
2626
*/
27-
class ExpressionVoter implements VoterInterface
27+
class ExpressionVoter implements CacheableVoterInterface
2828
{
2929
private ExpressionLanguage $expressionLanguage;
3030
private AuthenticationTrustResolverInterface $trustResolver;
@@ -39,6 +39,16 @@ public function __construct(ExpressionLanguage $expressionLanguage, Authenticati
3939
$this->roleHierarchy = $roleHierarchy;
4040
}
4141

42+
public function supportsAttribute(string $attribute): bool
43+
{
44+
return false;
45+
}
46+
47+
public function supportsType(string $subjectType): bool
48+
{
49+
return true;
50+
}
51+
4252
/**
4353
* {@inheritdoc}
4454
*/

Exception/AuthenticationException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@
2121
*/
2222
class AuthenticationException extends RuntimeException
2323
{
24+
/** @internal */
25+
protected $serialized;
26+
2427
private ?TokenInterface $token = null;
2528

29+
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
30+
{
31+
unset($this->serialized);
32+
parent::__construct($message, $code, $previous);
33+
}
34+
2635
public function getToken(): ?TokenInterface
2736
{
2837
return $this->token;

Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,31 @@ public function testCacheableVotersNotCalled()
202202
$this->assertFalse($manager->decide($token, ['foo'], 'bar'));
203203
}
204204

205+
public function testCacheableVotersWithMultipleAttributesAndNonString()
206+
{
207+
$token = $this->createMock(TokenInterface::class);
208+
$voter = $this->getMockBuilder(CacheableVoterInterface::class)->getMockForAbstractClass();
209+
$voter
210+
->expects($this->once())
211+
->method('supportsAttribute')
212+
->with('foo')
213+
->willReturn(false);
214+
$voter
215+
// Voter does not support "foo", but given 1337 is not a string, it implicitly supports it.
216+
->expects($this->once())
217+
->method('supportsType')
218+
->with('string')
219+
->willReturn(true);
220+
$voter
221+
->expects($this->once())
222+
->method('vote')
223+
->with($token, 'bar', ['foo', 1337])
224+
->willReturn(VoterInterface::ACCESS_GRANTED);
225+
226+
$manager = new AccessDecisionManager([$voter]);
227+
$this->assertTrue($manager->decide($token, ['foo', 1337], 'bar', true));
228+
}
229+
205230
protected function getVoters($grants, $denies, $abstains)
206231
{
207232
$voters = [];

Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
class ChildCustomUserMessageAuthenticationException extends CustomUserMessageAuthenticationException
2020
{
21+
public $childMember;
22+
2123
public function __serialize(): array
2224
{
2325
return [$this->childMember, parent::__serialize()];

0 commit comments

Comments
 (0)