Skip to content

Commit d0a175b

Browse files
committed
fixes #1659
1 parent f300ede commit d0a175b

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\Securitybundle\Tests\Functional;
4+
5+
class AuthenticationCommencingTest extends WebTestCase
6+
{
7+
public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
8+
{
9+
$client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => 'config.yml'));
10+
$client->insulate();
11+
12+
$client->request('GET', '/secure-but-not-covered-by-access-control');
13+
$this->assertRedirect($client->getResponse(), '/login');
14+
}
15+
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Controller/LoginController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FormLoginBundle\Controller;
1313

14+
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
1415
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\Security\Core\SecurityContext;
1617
use Symfony\Component\DependencyInjection\ContainerAware;
@@ -42,4 +43,9 @@ public function loginCheckAction()
4243
{
4344
return new Response('', 400);
4445
}
46+
47+
public function secureAction()
48+
{
49+
throw new \Exception('Wrapper', 0, new \Exception('Another Wrapper', 0, new AccessDeniedException()));
50+
}
4551
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/FormLoginBundle/Resources/config/routing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ form_login_redirect_to_protected_resource_after_login:
2525
form_logout:
2626
pattern: /logout_path
2727

28+
form_secure_action:
29+
pattern: /secure-but-not-covered-by-access-control
30+
defaults: { _controller: FormLoginBundle:Login:secure }

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/StandardFormLogin/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ security:
2626

2727
access_control:
2828
- { path: ^/unprotected_resource$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
29+
- { path: ^/secure-but-not-covered-by-access-control$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
2930
- { path: ^/highly_protected_resource$, roles: IS_ADMIN }
3031
- { path: .*, roles: IS_AUTHENTICATED_FULLY }

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public function onKernelException(GetResponseForExceptionEvent $event)
7676
$exception = $event->getException();
7777
$request = $event->getRequest();
7878

79+
// determine the actual cause for the exception
80+
while (null !== $previous = $exception->getPrevious()) {
81+
$exception = $previous;
82+
}
83+
7984
if ($exception instanceof AuthenticationException) {
8085
if (null !== $this->logger) {
8186
$this->logger->info(sprintf('Authentication exception occurred; redirecting to authentication entry point (%s)', $exception->getMessage()));

0 commit comments

Comments
 (0)