-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Be able to know the reasons of the denied access #35592
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
Changes from 1 commit
26a8381
868b9ff
edfc392
ec41df2
842e59e
7339108
8ef8d19
c8a360c
c4cfb5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -55,7 +55,15 @@ final public function isGranted($attribute, $subject = null): bool | |||
$this->tokenStorage->setToken($token = $this->authenticationManager->authenticate($token)); | ||||
} | ||||
|
||||
return ($this->lastAccessDecision = $this->accessDecisionManager->decide($token, [$attribute], $subject))->isGranted(); | ||||
$this->lastAccessDecision = $this->accessDecisionManager->decide($token, [$attribute], $subject); | ||||
|
||||
if (\is_bool($this->lastAccessDecision)) { | ||||
trigger_deprecation('symfony/security', 5.1, 'Returning a boolean from the "%s::decide()" method is deprecated. Return an "%s" object instead', \get_class($this->accessDecisionManager), AccessDecision::class); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
||||
return $this->lastAccessDecision; | ||||
} | ||||
|
||||
return $this->lastAccessDecision->isGranted(); | ||||
} | ||||
|
||||
public function getLastAccessDecision(): AccessDecision | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
trait AccessTrait | ||
{ | ||
/** @var int */ | ||
maidmaid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private $access; | ||
protected $access; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be private. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already discussed here #35592 (comment). Ok for you ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure to understand the rationale there. |
||
|
||
public function getAccess(): int | ||
{ | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
|
||
use Symfony\Component\Security\Core\Authorization\AccessDecision; | ||
use Symfony\Component\Security\Core\Authorization\Voter\Vote; | ||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; | ||
|
||
/** | ||
* AccessDeniedException is thrown when the account has not the required role. | ||
|
@@ -70,7 +69,7 @@ public function setSubject($subject) | |
public function setAccessDecision(AccessDecision $accessDecision) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this cannot be stateful IMHO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you suggest ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could make it stateless and have a specific exception render for AccessDeniedException. WDYT ? |
||
{ | ||
$this->accessDecision = $accessDecision; | ||
$reasons = array_map(function (Vote $vote) { return $vote->getReason(); }, $this->accessDecision->getVotes(VoterInterface::ACCESS_DENIED)); | ||
$reasons = array_map(function (Vote $vote) { return $vote->getReason(); }, $this->accessDecision->getDeniedVotes()); | ||
$this->message .= rtrim(' '.implode(' ', $reasons)); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.