Skip to content

Commit

Permalink
Remove symfony/security-acl dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Feb 25, 2024
1 parent 38862ea commit 0efd28b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/options-resolver": "^6.4 || ^7.0",
"symfony/routing": "^6.4 || ^7.0",
"symfony/security-acl": "^3.0",
"symfony/security-core": "^6.4 || ^7.0",
"symfony/security-csrf": "^6.4 || ^7.0",
"symfony/security-http": "^6.4 || ^7.0",
Expand Down
57 changes: 43 additions & 14 deletions src/Security/Authorization/Voter/UserAclVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,62 @@
namespace Nucleos\UserAdminBundle\Security\Authorization\Voter;

use Nucleos\UserBundle\Model\UserInterface;
use Symfony\Component\Security\Acl\Voter\AclVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\CacheableVoterInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

final class UserAclVoter extends AclVoter
if (class_exists(\Symfony\Component\Security\Core\Security::class)) {
/**
* @internal
*/
trait AclVoterTrait
{
public function vote(TokenInterface $token, $subject, array $attributes)
{
return $this->doVote($token, $subject, $attributes);

Check warning on line 29 in src/Security/Authorization/Voter/UserAclVoter.php

View check run for this annotation

Codecov / codecov/patch

src/Security/Authorization/Voter/UserAclVoter.php#L29

Added line #L29 was not covered by tests
}
}
} else {
/**
* @internal
*/
trait AclVoterTrait
{
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
{
return $this->doVote($token, $subject, $attributes);
}
}
}

final class UserAclVoter implements VoterInterface, CacheableVoterInterface
{
use AclVoterTrait;

/**
* @deprecated without any replace
*
* @param mixed $class
*/
public function supportsClass($class): bool
{
return is_subclass_of($class, UserInterface::class);
}

/**
* @param mixed|string $attribute
*/
public function supportsAttribute($attribute): bool
public function supportsType(string $subjectType): bool
{
return is_subclass_of($subjectType, UserInterface::class);
}

public function supportsAttribute(string $attribute): bool
{
return 'EDIT' === $attribute || 'DELETE' === $attribute;
}

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @param mixed $subject
*/
public function vote(TokenInterface $token, $subject, array $attributes): int
private function doVote(TokenInterface $token, mixed $subject, array $attributes): int

Check failure on line 72 in src/Security/Authorization/Voter/UserAclVoter.php

View workflow job for this annotation

GitHub Actions / run / Static Code Analysis (8.3)

Method Nucleos\UserAdminBundle\Security\Authorization\Voter\UserAclVoter::doVote() has parameter $attributes with no value type specified in iterable type array.
{
if (!$this->isValidSubject($subject)) {
return self::ACCESS_ABSTAIN;
Expand All @@ -58,11 +90,8 @@ public function vote(TokenInterface $token, $subject, array $attributes): int
return self::ACCESS_ABSTAIN;
}

/**
* @param mixed $subject
*/
private function isValidSubject($subject): bool
private function isValidSubject(mixed $subject): bool
{
return \is_object($subject) && $this->supportsClass(\get_class($subject));
return \is_object($subject) && $this->supportsType(\get_class($subject));
}
}

0 comments on commit 0efd28b

Please sign in to comment.