|
12 | 12 | namespace FOS\RestBundle\EventListener; |
13 | 13 |
|
14 | 14 | use FOS\RestBundle\FOSRestBundle; |
15 | | -use Psr\Log\LoggerInterface; |
16 | 15 | use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
17 | | -use Symfony\Component\HttpKernel\EventListener\ExceptionListener; |
18 | 16 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
19 | 17 | use Symfony\Component\HttpKernel\Exception\HttpException; |
20 | 18 | use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; |
21 | 19 | use Symfony\Component\HttpKernel\KernelEvents; |
22 | 20 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
23 | 21 | use Symfony\Component\Security\Core\Exception\AuthenticationException; |
| 22 | +use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
24 | 23 |
|
25 | 24 | /** |
26 | 25 | * This listener handles ensures that for specific formats AccessDeniedExceptions |
|
30 | 29 | * |
31 | 30 | * @internal |
32 | 31 | */ |
33 | | -class AccessDeniedListener extends ExceptionListener |
| 32 | +class AccessDeniedListener implements EventSubscriberInterface |
34 | 33 | { |
35 | 34 | private $formats; |
36 | 35 | private $challenge; |
37 | 36 |
|
38 | 37 | /** |
39 | 38 | * Constructor. |
40 | 39 | * |
41 | | - * @param array $formats An array with keys corresponding to request formats or content types |
42 | | - * that must be processed by this listener |
43 | | - * @param string $challenge |
44 | | - * @param string $controller |
45 | | - * @param LoggerInterface $logger |
| 40 | + * @param array $formats An array with keys corresponding to request formats or content types |
| 41 | + * that must be processed by this listener |
| 42 | + * @param string $challenge |
46 | 43 | */ |
47 | | - public function __construct($formats, $challenge, $controller, LoggerInterface $logger = null) |
| 44 | + public function __construct($formats, $challenge) |
48 | 45 | { |
49 | 46 | $this->formats = $formats; |
50 | 47 | $this->challenge = $challenge; |
51 | | - parent::__construct($controller, $logger); |
52 | 48 | } |
53 | 49 |
|
54 | 50 | public function onKernelException(GetResponseForExceptionEvent $event) |
@@ -76,15 +72,13 @@ public function onKernelException(GetResponseForExceptionEvent $event) |
76 | 72 | if ($exception instanceof AccessDeniedException) { |
77 | 73 | $exception = new AccessDeniedHttpException('You do not have the necessary permissions', $exception); |
78 | 74 | $event->setException($exception); |
79 | | - parent::onKernelException($event); |
80 | 75 | } elseif ($exception instanceof AuthenticationException) { |
81 | 76 | if ($this->challenge) { |
82 | 77 | $exception = new UnauthorizedHttpException($this->challenge, 'You are not authenticated', $exception); |
83 | 78 | } else { |
84 | 79 | $exception = new HttpException(401, 'You are not authenticated', $exception); |
85 | 80 | } |
86 | 81 | $event->setException($exception); |
87 | | - parent::onKernelException($event); |
88 | 82 | } |
89 | 83 |
|
90 | 84 | $handling = false; |
|
0 commit comments