This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle
Fabien Potencier 90f7ff50c8 feature #19473 [Security] Expose the required roles in AccessDeniedException (Nicofuma)
This PR was merged into the 3.2-dev branch.

Discussion
----------

[Security] Expose the required roles in AccessDeniedException

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Nowadays it is more and more common to protect some sensitive actions and part of a website using 2FA or some re-authentication mechanism (per example, on Github you have to enter your password again when you add an ssh key). But currently, in Symfony, it is really hard to implement without having to duplicate the logic, provide an explicit list of URLs to protect or hack into the security component.

A good way to achieve that would be to add a special role (like IS_AUTHENTICATED_FULLY) and use it in the access map. But it requires us to be able to have a custom logic in an ExceptionListener depending on the roles behind an AccessDeniedException.

With this patch we could write an ExceptionListener of this kind (a similar logic could also be used in an AccessDeniedHandler):

```php
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        do {
            if ($exception instanceof AccessDeniedException) {
                foreach ($exception->getAttributes() as $role) {
                    if ($role === 'IS_AUTHENTICATED_2FA' && !$this->accessDecisionManager->decide($this->tokenStorage->getToken(), $role, $exception->getObject())) {
                        // Start 2FA
                    }
                }
            }
        } while (null !== $exception = $exception->getPrevious());
    }
```

Replaces #18661

Commits
-------

6618c18 [Security] Expose the required roles in AccessDeniedException
2016-08-09 06:40:33 -07:00
..
CacheWarmer [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations 2016-07-30 03:40:00 -04:00
Command Merge branch '3.1' 2016-07-26 10:08:27 +02:00
Console [Console][FrameworkBundle] Revised console header formatting 2016-07-29 05:54:38 -04:00
Controller [Security] Expose the required roles in AccessDeniedException 2016-07-29 17:08:58 +02:00
DataCollector [FrameworkBundle] Extends the RequestDataCollector 2016-03-30 19:02:53 +02:00
DependencyInjection feature #18533 [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations (tgalopin) 2016-07-30 03:40:02 -04:00
EventListener [2.3] CS And DocBlock Fixes 2014-12-22 16:58:09 +01:00
HttpCache Silence invasive deprecation warnings, opt-in for warnings 2015-06-08 10:37:21 +01:00
Kernel added a micro kernel 2015-11-04 18:19:57 +01:00
Resources [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations 2016-07-30 03:40:00 -04:00
Routing Merge branch '2.8' into 3.0 2016-06-29 07:40:00 +02:00
Templating Merge branch '3.0' into 3.1 2016-06-29 07:41:56 +02:00
Test Merge branch '2.7' into 2.8 2016-01-07 14:38:40 +01:00
Tests feature #18533 [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations (tgalopin) 2016-07-30 03:40:02 -04:00
Translation Merge branch '2.8' into 3.0 2016-07-26 10:03:56 +02:00
Validator [Validator] Removed legacy validator classes 2014-08-06 15:23:29 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md Added a SecurityUserValueResolver for controllers 2016-07-01 08:00:40 +02:00
Client.php Merge branch '2.3' into 2.7 2016-03-16 17:00:15 +01:00
composer.json feature #19473 [Security] Expose the required roles in AccessDeniedException (Nicofuma) 2016-08-09 06:40:33 -07:00
FrameworkBundle.php [FrameworkBundle] Add cache-pool tag and wiring 2016-04-04 11:41:14 +02:00
LICENSE Move licenses according to new best practices 2016-01-31 22:16:42 +01:00
phpunit.xml.dist Add missing exclusions from phpunit.xml.dist 2015-11-18 09:19:46 +01:00
README.md add readme files where missing 2016-03-07 11:36:15 +01:00