Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfd0812

Browse files
Merge branch '6.4' into 7.0
* 6.4: [SecurityBundle] Deprecate `Security::*` consts and other cleanups [Security] Remove ArgumentValueResolverInterface from UserValueResolver
2 parents 9e248b8 + 29c1efa commit cfd0812

File tree

6 files changed

+60
-21
lines changed

6 files changed

+60
-21
lines changed

.github/patch-types.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// no break;
2525
case false !== strpos($file, '/vendor/'):
2626
case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'):
27+
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/ContainerAwareController.php'):
2728
case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'):
2829
case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'):
2930
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'):

src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ CHANGELOG
66

77
* Enabling SecurityBundle and not configuring it is not allowed
88

9+
6.4
10+
---
11+
12+
* Deprecate `Security::ACCESS_DENIED_ERROR`, `AUTHENTICATION_ERROR` and `LAST_USERNAME` constants, use the ones on `SecurityRequestAttributes` instead
13+
914
6.3
1015
---
1116

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function prepend(ContainerBuilder $container): void
9191
public function load(array $configs, ContainerBuilder $container): void
9292
{
9393
if (!array_filter($configs)) {
94-
throw new InvalidArgumentException(sprintf('Enabling bundle "%s" and not configuring it is not allowed.', SecurityBundle::class));
94+
throw new InvalidConfigurationException(sprintf('Enabling bundle "%s" and not configuring it is not allowed.', SecurityBundle::class));
9595
}
9696

9797
$mainConfig = $this->getConfiguration($configs, $container);
@@ -184,17 +184,14 @@ public function load(array $configs, ContainerBuilder $container): void
184184
$container->getDefinition('security.authorization_checker')->setArgument(3, false);
185185
}
186186

187-
/**
188-
* @throws \InvalidArgumentException if the $strategy is invalid
189-
*/
190187
private function createStrategyDefinition(string $strategy, bool $allowIfAllAbstainDecisions, bool $allowIfEqualGrantedDeniedDecisions): Definition
191188
{
192189
return match ($strategy) {
193190
MainConfiguration::STRATEGY_AFFIRMATIVE => new Definition(AffirmativeStrategy::class, [$allowIfAllAbstainDecisions]),
194191
MainConfiguration::STRATEGY_CONSENSUS => new Definition(ConsensusStrategy::class, [$allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions]),
195192
MainConfiguration::STRATEGY_UNANIMOUS => new Definition(UnanimousStrategy::class, [$allowIfAllAbstainDecisions]),
196193
MainConfiguration::STRATEGY_PRIORITY => new Definition(PriorityStrategy::class, [$allowIfAllAbstainDecisions]),
197-
default => throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy)),
194+
default => throw new InvalidConfigurationException(sprintf('The strategy "%s" is not supported.', $strategy)),
198195
};
199196
}
200197

src/Symfony/Bundle/SecurityBundle/Security.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
19+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
20+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1921
use Symfony\Component\Security\Core\Exception\LogicException;
2022
use Symfony\Component\Security\Core\Exception\LogoutException;
2123
use Symfony\Component\Security\Core\Security as LegacySecurity;
@@ -27,6 +29,17 @@
2729
use Symfony\Component\Security\Http\SecurityRequestAttributes;
2830
use Symfony\Contracts\Service\ServiceProviderInterface;
2931

32+
if (class_exists(LegacySecurity::class)) {
33+
class_alias(LegacySecurity::class, InternalSecurity::class);
34+
} else {
35+
/**
36+
* @internal
37+
*/
38+
class InternalSecurity
39+
{
40+
}
41+
}
42+
3043
/**
3144
* Helper class for commonly-needed security tasks.
3245
*
@@ -36,15 +49,50 @@
3649
*
3750
* @final
3851
*/
39-
class Security extends LegacySecurity
52+
class Security extends InternalSecurity implements AuthorizationCheckerInterface
4053
{
54+
/**
55+
* @deprecated since Symfony 6.4, use SecurityRequestAttributes::ACCESS_DENIED_ERROR instead
56+
*/
4157
public const ACCESS_DENIED_ERROR = SecurityRequestAttributes::ACCESS_DENIED_ERROR;
58+
59+
/**
60+
* @deprecated since Symfony 6.4, use SecurityRequestAttributes::ACCESS_DENIED_ERROR instead
61+
*/
4262
public const AUTHENTICATION_ERROR = SecurityRequestAttributes::AUTHENTICATION_ERROR;
63+
64+
/**
65+
* @deprecated since Symfony 6.4, use SecurityRequestAttributes::ACCESS_DENIED_ERROR instead
66+
*/
4367
public const LAST_USERNAME = SecurityRequestAttributes::LAST_USERNAME;
4468

45-
public function __construct(private readonly ContainerInterface $container, private readonly array $authenticators = [])
69+
public function __construct(
70+
private readonly ContainerInterface $container,
71+
private readonly array $authenticators = [],
72+
) {
73+
}
74+
75+
public function getUser(): ?UserInterface
76+
{
77+
if (!$token = $this->getToken()) {
78+
return null;
79+
}
80+
81+
return $token->getUser();
82+
}
83+
84+
/**
85+
* Checks if the attributes are granted against the current authentication token and optionally supplied subject.
86+
*/
87+
public function isGranted(mixed $attributes, mixed $subject = null): bool
88+
{
89+
return $this->container->get('security.authorization_checker')
90+
->isGranted($attributes, $subject);
91+
}
92+
93+
public function getToken(): ?TokenInterface
4694
{
47-
parent::__construct($container, false);
95+
return $this->container->get('security.token_storage')->getToken();
4896
}
4997

5098
public function getFirewallConfig(Request $request): ?FirewallConfig

src/Symfony/Component/Security/Core/Security.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,8 @@
2424
*/
2525
class Security implements AuthorizationCheckerInterface
2626
{
27-
/**
28-
* @deprecated since Symfony 6.2, use \Symfony\Bundle\SecurityBundle\Security::ACCESS_DENIED_ERROR instead
29-
*/
3027
public const ACCESS_DENIED_ERROR = '_security.403_error';
31-
32-
/**
33-
* @deprecated since Symfony 6.2, use \Symfony\Bundle\SecurityBundle\Security::AUTHENTICATION_ERROR instead
34-
*/
3528
public const AUTHENTICATION_ERROR = '_security.last_error';
36-
37-
/**
38-
* @deprecated since Symfony 6.2, use \Symfony\Bundle\SecurityBundle\Security::LAST_USERNAME instead
39-
*/
4029
public const LAST_USERNAME = '_security.last_username';
4130

4231
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Security\Http\Controller;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15-
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
1615
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
1716
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
1817
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -25,7 +24,7 @@
2524
*
2625
* @author Iltar van der Berg <[email protected]>
2726
*/
28-
final class UserValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
27+
final class UserValueResolver implements ValueResolverInterface
2928
{
3029
private TokenStorageInterface $tokenStorage;
3130

0 commit comments

Comments
 (0)