diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | Core/Exception/AccessDeniedException.php | 35 | ||||
-rw-r--r-- | Http/Firewall/AccessListener.php | 6 | ||||
-rw-r--r-- | Http/Firewall/SwitchUserListener.php | 5 | ||||
-rw-r--r-- | Http/composer.json | 2 |
5 files changed, 50 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 107ed1d..f92742a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +3.2.0 +----- + + * added `attributes` and `object` with getters/setters to `Symfony\Component\Security\Core\Exception\AccessDeniedException` + 3.0.0 ----- diff --git a/Core/Exception/AccessDeniedException.php b/Core/Exception/AccessDeniedException.php index 736a36b..d9a7019 100644 --- a/Core/Exception/AccessDeniedException.php +++ b/Core/Exception/AccessDeniedException.php @@ -18,8 +18,43 @@ namespace Symfony\Component\Security\Core\Exception; */ class AccessDeniedException extends \RuntimeException { + private $attributes = array(); + private $object; + public function __construct($message = 'Access Denied.', \Exception $previous = null) { parent::__construct($message, 403, $previous); } + + /** + * @return array + */ + public function getAttributes() + { + return $this->attributes; + } + + /** + * @param array|string $attributes + */ + public function setAttributes($attributes) + { + $this->attributes = (array) $attributes; + } + + /** + * @return mixed + */ + public function getObject() + { + return $this->object; + } + + /** + * @param mixed $object + */ + public function setObject($object) + { + $this->object = $object; + } } diff --git a/Http/Firewall/AccessListener.php b/Http/Firewall/AccessListener.php index c234317..5a23666 100644 --- a/Http/Firewall/AccessListener.php +++ b/Http/Firewall/AccessListener.php @@ -67,7 +67,11 @@ class AccessListener implements ListenerInterface } if (!$this->accessDecisionManager->decide($token, $attributes, $request)) { - throw new AccessDeniedException(); + $exception = new AccessDeniedException(); + $exception->setAttributes($attributes); + $exception->setObject($request); + + throw $exception; } } } diff --git a/Http/Firewall/SwitchUserListener.php b/Http/Firewall/SwitchUserListener.php index 7de83d2..e9c3e40 100644 --- a/Http/Firewall/SwitchUserListener.php +++ b/Http/Firewall/SwitchUserListener.php @@ -122,7 +122,10 @@ class SwitchUserListener implements ListenerInterface } if (false === $this->accessDecisionManager->decide($token, array($this->role))) { - throw new AccessDeniedException(); + $exception = new AccessDeniedException(); + $exception->setAttributes($this->role); + + throw $exception; } $username = $request->get($this->usernameParameter); diff --git a/Http/composer.json b/Http/composer.json index 3f98ec5..add5d3a 100644 --- a/Http/composer.json +++ b/Http/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.5.9", - "symfony/security-core": "~2.8|~3.0", + "symfony/security-core": "~3.2", "symfony/event-dispatcher": "~2.8|~3.0", "symfony/http-foundation": "~2.8|~3.0", "symfony/http-kernel": "~2.8|~3.0", |