8000 Delegate to DefaultValueResolver if a default value is present and no… · symfony/symfony@733cd9a · GitHub
[go: up one dir, main page]

Skip to content

Commit 733cd9a

Browse files
committed
Delegate to DefaultValueResolver if a default value is present and no user is logged in
1 parent 7839261 commit 733cd9a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Security/Http/Controller/UserValueResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
4141
return false;
4242
}
4343

44+
// if no user is present but a default value exists we delegate to DefaultValueResolver
45+
if ($argument->hasDefaultValue() && null === $this->tokenStorage->getToken()?->getUser()) {
46+
return false;
47+
}
48+
4449
return true;
4550
}
4651

src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function testSupportsFailsWithNoType()
3636
$this->assertFalse($resolver->supports(Request::create('/'), $metadata));
3737
}
3838

39+
public function testSupportsFailsWhenDefaultValAndNoUser()
40+
{
41+
$tokenStorage = new TokenStorage();
42+
$resolver = new UserValueResolver($tokenStorage);
43+
$metadata = new ArgumentMetadata('foo', UserInterface::class, false, true, new InMemoryUser('username', 'password'));
44+
45+
$this->assertFalse($resolver->supports(Request::create('/'), $metadata));
46+
}
47+
3948
public function testResolveSucceedsWithUserInterface()
4049
{
4150
$user = new InMemoryUser('username', 'password');

0 commit comments

Comments
 (0)
0