Skip to content

Commit d4428cf

Browse files
committed
Merge branch '2.3' into 2.5
* 2.3: [SecurityBundle] Authentication entry point is only registered with firewall exception listener, not with authentication listeners be smarter when guessing the document root Azerbaijani locale Fixed grammar error in docblock Adjust upgrade file rendering [Bridge/Propel1] Changed deps to accepts all upcoming propel1 versions compare version using PHP_VERSION_ID [Form] Add doc for FormEvents don't override internal PHP constants Conflicts: UPGRADE-3.0.md src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Component/Debug/ErrorHandler.php src/Symfony/Component/HttpFoundation/Response.php
2 parents b8fcebc + cdee77f commit d4428cf

File tree

10 files changed

+181
-10
lines changed

10 files changed

+181
-10
lines changed

DependencyInjection/SecurityExtension.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,11 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
349349
;
350350
}
351351

352+
// Determine default entry point
353+
$defaultEntryPoint = isset($firewall['entry_point']) ? $firewall['entry_point'] : null;
354+
352355
// Authentication listeners
353-
list($authListeners, $defaultEntryPoint) = $this->createAuthenticationListeners($container, $id, $firewall, $authenticationProviders, $defaultProvider);
356+
list($authListeners, $defaultEntryPoint) = $this->createAuthenticationListeners($container, $id, $firewall, $authenticationProviders, $defaultProvider, $defaultEntryPoint);
354357

355358
$listeners = array_merge($listeners, $authListeners);
356359

@@ -362,11 +365,6 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
362365
// Access listener
363366
$listeners[] = new Reference('security.access_listener');
364367

365-
// Determine default entry point
366-
if (isset($firewall['entry_point'])) {
367-
$defaultEntryPoint = $firewall['entry_point'];
368-
}
369-
370368
// Exception listener
371369
$exceptionListener = new Reference($this->createExceptionListener($container, $firewall, $id, $defaultEntryPoint));
372370

@@ -386,11 +384,10 @@ private function createContextListener($container, $contextKey)
386384
return $this->contextListeners[$contextKey] = $listenerId;
387385
}
388386

389-
private function createAuthenticationListeners($container, $id, $firewall, &$authenticationProviders, $defaultProvider)
387+
private function createAuthenticationListeners($container, $id, $firewall, &$authenticationProviders, $defaultProvider, $defaultEntryPoint)
390388
{
391389
$listeners = array();
392390
$hasListeners = false;
393-
$defaultEntryPoint = null;
394391

395392
foreach ($this->listenerPositions as $position) {
396393
foreach ($this->factories[$position] as $factory) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\DependencyInjection;
13+
14+
use Symfony\Component\Config\FileLocator;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
17+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18+
19+
class FirewallEntryPointExtension extends Extension
20+
{
21+
public function load(array $config, ContainerBuilder $container)
22+
{
23+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
24+
$loader->load('services.xml');
25+
}
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class FirewallEntryPointBundle extends Bundle
17+
{
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
<services>
6+
<service id="firewall_entry_point.entry_point.stub"
7+
class="Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\Security\EntryPointStub"
8+
/>
9+
</services>
10+
</container>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\Security;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
17+
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
18+
19+
class EntryPointStub implements AuthenticationEntryPointInterface
20+
{
21+
const RESPONSE_TEXT = '2be8e651259189d841a19eecdf37e771e2431741';
22+
23+
public function start(Request $request, AuthenticationException $authException = null)
24+
{
25+
return new Response(self::RESPONSE_TEXT);
26+
}
27+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
13+
14+
use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\Security\EntryPointStub;
15+
16+
/**
17+
* @group functional
18+
*/
19+
class FirewallEntryPointTest extends WebTestCase
20+
{
21+
public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials()
22+
{
23+
$client = $this->createClient(array('test_case' => 'FirewallEntryPoint'));
24+
$client->insulate();
25+
26+
$client->request('GET', '/secure/resource', array(), array(), array(
27+
'PHP_AUTH_USER' => 'unknown',
28+
'PHP_AUTH_PW' => 'credentials',
29+
));
30+
31+
$this->assertEquals(
32+
EntryPointStub::RESPONSE_TEXT,
33+
$client->getResponse()->getContent(),
34+
"Custom entry point wasn't started"
35+
);
36+
}
37+
38+
protected function setUp()
39+
{
40+
parent::setUp();
41+
42+
$this->deleteTmpDir('FirewallEntryPoint');
43+
}
44+
45+
protected function tearDown()
46+
{
47+
parent::tearDown();
48+
49+
$this->deleteTmpDir('FirewallEntryPoint');
50+
}
51+
}

Tests/Functional/SecurityRoutingIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($c
3030
*/
3131
public function testRoutingErrorIsExposedWhenNotProtected($config)
3232
{
33-
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
33+
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
3434
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
3535
}
3636

@@ -46,7 +46,7 @@ public function testRoutingErrorIsExposedWhenNotProtected($config)
4646
*/
4747
public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
4848
{
49-
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
49+
if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50309) {
5050
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
5151
}
5252

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return array(
4+
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
5+
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
6+
new Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\FirewallEntryPointBundle(),
7+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
framework:
2+
secret: test
3+
csrf_protection:
4+
enabled: true
5+
router: { resource: "%kernel.root_dir%/%kernel.test_case%/routing.yml" }
6+
validation: { enabled: true, enable_annotations: true }
7+
form: ~
8+
test: ~
9+
default_locale: en
10+
session:
11+
storage_id: session.storage.mock_file
12+
profiler: { only_exceptions: false }
13+
14+
services:
15+
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }
16+
17+
security:
18+
firewalls:
19+
secure:
20+
pattern: ^/secure/
21+
http_basic: { realm: "Secure Gateway API" }
22+
entry_point: firewall_entry_point.entry_point.stub
23+
default:
24+
anonymous: ~
25+
access_control:
26+
- { path: ^/secure/, roles: ROLE_SECURE }
27+
providers:
28+
in_memory:
29+
memory:
30+
users:
31+
john: { password: doe, roles: [ROLE_SECURE] }
32+
encoders:
33+
Symfony\Component\Security\Core\User\User: plaintext
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
secure_resource:
2+
path: /secure/resource

0 commit comments

Comments
 (0)