Skip to content

[Security][SecurityBundle] rename userIsGranted() to isGrantedForUser() #59214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CHANGELOG
7.3
---

* Add `Security::userIsGranted()` to test user authorization without relying on the session. For example, users not currently logged in, or while processing a message from a message queue
* Add `Security::isGrantedForUser()` to test user authorization without relying on the session. For example, users not currently logged in, or while processing a message from a message queue

7.2
---
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/SecurityBundle/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public function logout(bool $validateCsrfToken = true): ?Response
*
* This should be used over isGranted() when checking permissions against a user that is not currently logged in or while in a CLI context.
*/
public function userIsGranted(UserInterface $user, mixed $attribute, mixed $subject = null): bool
public function isGrantedForUser(UserInterface $user, mixed $attribute, mixed $subject = null): bool
{
return $this->container->get('security.user_authorization_checker')
->userIsGranted($user, $attribute, $subject);
->isGrantedForUser($user, $attribute, $subject);
}

private function getAuthenticator(?string $authenticatorName, string $firewallName): AuthenticatorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function testUserAuthorizationChecker()
$security = $container->get('functional_test.security.helper');
$this->assertTrue($security->isGranted('ROLE_FOO'));
$this->assertFalse($security->isGranted('ROLE_BAR'));
$this->assertTrue($security->userIsGranted($offlineUser, 'ROLE_BAR'));
$this->assertFalse($security->userIsGranted($offlineUser, 'ROLE_FOO'));
$this->assertTrue($security->isGrantedForUser($offlineUser, 'ROLE_BAR'));
$this->assertFalse($security->isGrantedForUser($offlineUser, 'ROLE_FOO'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
) {
}

public function userIsGranted(UserInterface $user, mixed $attribute, mixed $subject = null): bool
public function isGrantedForUser(UserInterface $user, mixed $attribute, mixed $subject = null): bool
{
return $this->accessDecisionManager->decide(new UserAuthorizationCheckerToken($user), [$attribute], $subject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ interface UserAuthorizationCheckerInterface
*
* @param mixed $attribute A single attribute to vote on (can be of any type, string and instance of Expression are supported by the core)
*/
public function userIsGranted(UserInterface $user, mixed $attribute, mixed $subject = null): bool;
public function isGrantedForUser(UserInterface $user, mixed $attribute, mixed $subject = null): bool;
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Security/Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CHANGELOG
7.3
---

* Add `UserAuthorizationChecker::userIsGranted()` to test user authorization without relying on the session.
* Add `UserAuthorizationChecker::isGrantedForUser()` to test user authorization without relying on the session.
For example, users not currently logged in, or while processing a message from a message queue.
* Add `OfflineTokenInterface` to mark tokens that do not represent the currently logged-in user

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testIsGranted(bool $decide, array $roles)
->with($this->callback(fn (UserAuthorizationCheckerToken $token): bool => $user === $token->getUser()), $this->identicalTo(['ROLE_FOO']))
->willReturn($decide);

$this->assertSame($decide, $this->authorizationChecker->userIsGranted($user, 'ROLE_FOO'));
$this->assertSame($decide, $this->authorizationChecker->isGrantedForUser($user, 'ROLE_FOO'));
}

public static function isGrantedProvider(): array
Expand All @@ -65,6 +65,6 @@ public function testIsGrantedWithObjectAttribute()
->method('decide')
->with($this->isInstanceOf($token::class), $this->identicalTo([$attribute]))
->willReturn(true);
$this->assertTrue($this->authorizationChecker->userIsGranted($token->getUser(), $attribute));
$this->assertTrue($this->authorizationChecker->isGrantedForUser($token->getUser(), $attribute));
}
}