8000 [SecurityBundle] Support autowiring for AccessDecisionManagerInterface by unexge · Pull Request #19684 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[SecurityBundle] Support autowiring for AccessDecisionManagerInterface #19684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public function load(array $configs, ContainerBuilder $container)

if ($container->hasParameter('kernel.debug') && $container->getParameter('kernel.debug')) {
$loader->load('security_debug.xml');

if ($container->hasDefinition('security.access.decision_manager') && $container->hasDefinition('debug.security.access.decision_manager')) {
Copy link
Member
@dunglas dunglas Aug 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, the last loaded autowiring_types config will override previous ones. You can just add <autowiring-type>Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface</autowiring-type> to the debug.security.access.decision_manager definition and it should do the trick without having to touch the extension.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did this first, but it didn't work.

now i did some debugging, and i guess this didn't work because, this is a decorator service.

in this case, this services takes precedence in order:

  • security.access.decision_manager
  • debug.security.access.decision_manager
  • debug.security.access.decision_manager.inner (which is alias for security.access.decision_manager)

$container->getDefinition('security.access.decision_manager')->setAutowiringTypes(array());
$container->getDefinition('debug.security.access.decision_manager')->setAutowiringTypes(array('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface'));
}
}

if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<!-- Authorization related services -->
<service id="security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\AccessDecisionManager" public="false">
<argument type="collection" />

<autowiring-type>Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface</autowiring-type>
</service>

<service id="security.role_hierarchy" class="Symfony\Component\Security\Core\Role\RoleHierarchy" public="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;

class AutowiringTypesTest extends WebTestCase
{
public function testAccessDecisionManagerAutowiring()
{
static::bootKernel(array('debug' => false));
$container = static::$kernel->getContainer();

$accessDecisionManager = $container->get('test.autowiring_types.autowired_services')->getAccessDecisionManager();
$this->assertInstanceOf(AccessDecisionManager::class, $accessDecisionManager);
}

public function testDebugAccessDecisionManagerAutowiring()
{
static::bootKernel(array('debug' => true));
$container = static::$kernel->getContainer();

$accessDecisionManager = $container->get('test.autowiring_types.autowired_services')->getAccessDecisionManager();
$this->assertInstanceOf(DebugAccessDecisionManager::class, $accessDecisionManager);
}

protected static function createKernel(array $options = array())
{
return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes;

use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;

class AutowiredServices
{
private $accessDecisionManager;

public function __construct(AccessDecisionManagerInterface $accessDecisionManager)
{
$this->accessDecisionManager = $accessDecisionManager;
}

public function getAccessDecisionManager()
{
return $this->accessDecisionManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\TestBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class TestBundle extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

return array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\S 6D4E ecurityBundle(),
new Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\TestBundle\TestBundle(),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
imports:
- { resource: ../config/framework.yml }


security:
providers:
in_memory:
memory: ~

firewalls:
test:
pattern: ^/
security: false

services:
test.autowiring_types.autowired_services:
class: Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices
autowire: true
0