Skip to content

Commit 1b452e4

Browse files
committed
Merge branch '4.4'
* 4.4: [HttpKernel] make ExceptionEvent able to propagate any throwable [Security] Avoid unnecessary usage of Reflection Disallow symfony/contracts v2. minor add missing loop break [Security] Add migrating encoder configuration [Security] Fix defining multiple roles per access_control rule
2 parents f050000 + 4785fe8 commit 1b452e4

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

Firewall/AccessListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ public function __invoke(RequestEvent $event)
6666
$this->tokenStorage->setToken($token);
6767
}
6868

69-
if (!$this->accessDecisionManager->decide($token, $attributes, $request)) {
69+
$granted = false;
70+
foreach ($attributes as $key => $value) {
71+
if ($this->accessDecisionManager->decide($token, [$key => $value], $request)) {
72+
$granted = true;
73+
break;
74+
}
75+
}
76+
77+
if (!$granted) {
7078
$exception = new AccessDeniedException();
7179
$exception->setAttributes($attributes);
7280
$exception->setSubject($request);

Firewall/ExceptionListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function unregister(EventDispatcherInterface $dispatcher)
9090
*/
9191
public function onKernelException(ExceptionEvent $event)
9292
{
93-
$exception = $event->getException();
93+
$exception = $event->getThrowable();
9494
do {
9595
if ($exception instanceof AuthenticationException) {
9696
$this->handleAuthenticationException($event, $exception);
@@ -128,13 +128,13 @@ private function handleAuthenticationException(ExceptionEvent $event, Authentica
128128
$event->setResponse($this->startAuthentication($event->getRequest(), $exception));
129129
$event->allowCustomResponseCode();
130130
} catch (\Exception $e) {
131-
$event->setException($e);
131+
$event->setThrowable($e);
132132
}
133133
}
134134

135135
private function handleAccessDeniedException(ExceptionEvent $event, AccessDeniedException $exception)
136136
{
137-
$event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));
137+
$event->setThrowable(new AccessDeniedHttpException($exception->getMessage(), $exception));
138138

139139
$token = $this->tokenStorage->getToken();
140140
if (!$this->authenticationTrustResolver->isFullFledged($token)) {
@@ -148,7 +148,7 @@ private function handleAccessDeniedException(ExceptionEvent $event, AccessDenied
148148

149149
$event->setResponse($this->startAuthentication($event->getRequest(), $insufficientAuthenticationException));
150150
} catch (\Exception $e) {
151-
$event->setException($e);
151+
$event->setThrowable($e);
152152
}
153153

154154
return;
@@ -177,7 +177,7 @@ private function handleAccessDeniedException(ExceptionEvent $event, AccessDenied
177177
$this->logger->error('An exception was thrown when handling an AccessDeniedException.', ['exception' => $e]);
178178
}
179179

180-
$event->setException(new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
180+
$event->setThrowable(new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
181181
}
182182
}
183183

Tests/Firewall/ExceptionListenerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testAuthenticationExceptionWithoutEntryPoint(\Exception $excepti
3939
$listener->onKernelException($event);
4040

4141
$this->assertNull($event->getResponse());
42-
$this->assertEquals($eventException, $event->getException());
42+
$this->assertEquals($eventException, $event->getThrowable());
4343
}
4444

4545
/**
@@ -58,7 +58,7 @@ public function testAuthenticationExceptionWithEntryPoint(\Exception $exception)
5858

5959
$this->assertEquals('Forbidden', $event->getResponse()->getContent());
6060
$this->assertEquals(403, $event->getResponse()->getStatusCode());
61-
$this->assertSame($exception, $event->getException());
61+
$this->assertSame($exception, $event->getThrowable());
6262
}
6363

6464
public function getAuthenticationExceptionProvider()
@@ -85,8 +85,8 @@ public function testExceptionWhenEntryPointReturnsBadValue()
8585
$listener = $this->createExceptionListener(null, null, null, $entryPoint);
8686
$listener->onKernelException($event);
8787
// the exception has been replaced by our LogicException
88-
$this->assertInstanceOf('LogicException', $event->getException());
89-
$this->assertStringEndsWith('start() method must return a Response object (string returned)', $event->getException()->getMessage());
88+
$this->assertInstanceOf('LogicException', $event->getThrowable());
89+
$this->assertStringEndsWith('start() method must return a Response object (string returned)', $event->getThrowable()->getMessage());
9090
}
9191

9292
/**
@@ -100,7 +100,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandle
100100
$listener->onKernelException($event);
101101

102102
$this->assertNull($event->getResponse());
103-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
103+
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
104104
}
105105

106106
/**
@@ -123,7 +123,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandle
123123

124124
$this->assertEquals('Unauthorized', $event->getResponse()->getContent());
125125
$this->assertEquals(401, $event->getResponse()->getStatusCode());
126-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
126+
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
127127
}
128128

129129
/**
@@ -140,7 +140,7 @@ public function testAccessDeniedExceptionFullFledgedAndWithAccessDeniedHandlerAn
140140
$listener->onKernelException($event);
141141

142142
$this->assertEquals('error', $event->getResponse()->getContent());
143-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
143+
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
144144
}
145145

146146
/**
@@ -157,7 +157,7 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
157157
$listener->onKernelException($event);
158158

159159
$this->assertEquals('OK', $event->getResponse()->getContent());
160-
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getException()->getPrevious());
160+
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
161161
}
162162

163163
public function getAccessDeniedExceptionProvider()

0 commit comments

Comments
 (0)