Find the best Rector rule to solve your problem. Searching through 1009 rules.
Found 4 rules:
Remove unused UserInterface::eraseCredentials() method, make it part of serialize if needed
use Symfony\Component\Security\Core\User\UserInterface;
final class User implements UserInterface
{
- public function eraseCredentials()
- {
- // some logic here
- }
}
Replaces AuthorizationCheckerInterface with AccessDecisionManagerInterface inside Symfony Voters
-use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
+use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
final class AuthorizationCheckerVoter extends Voter
{
public function __construct(
- private AuthorizationCheckerInterface $authorizationChecker
+ private AccessDecisionManagerInterface $accessDecisionManager
) {}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
- return $this->authorizationChecker->isGranted('ROLE_ADMIN', $subject);
+ return $this->accessDecisionManager->decide($token, ['ROLE_ADMIN'], $subject);
}
}
Adds a new $voter argument in protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token, ?Vote $vote = null): bool
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
final class MyVoter extends Voter
{
protected function supports(string $attribute, mixed $subject): bool
{
return true;
}
- protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
+ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token, ?\Symfony\Component\Security\Core\Authorization\Voter\Vote $vote = null): bool
{
return true;
}
}
Change $this->authorizationChecker->isGranted([$a, $b]) to $this->authorizationChecker->isGranted($a) || $this->authorizationChecker->isGranted($b), also updates AbstractController usages
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
final class SomeController
{
public function __construct(
private AuthorizationCheckerInterface $authorizationChecker
) {
}
public function hasAccess(): bool
{
- if ($this->authorizationChecker->isGranted(['ROLE_USER', 'ROLE_ADMIN'])) {
+ if ($this->authorizationChecker->isGranted('ROLE_USER') || $this->authorizationChecker->isGranted('ROLE_ADMIN')) {
return true;
}
return false;
}
}