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

Skip to content

[SecurityBundle][2.8] Support autowiring for AccessDecisionManagerInterface #19941

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 8000

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 @@ -107,6 +107,8 @@
<!-- Authorization related services -->
<service id="security.access.decision_manager" class="%security.access.decision_manager.class%" public="false">
<argument type="collection" />

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

<service id="security.role_hierarchy" class="%security.role_hierarchy.class%" public="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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;

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

$accessDecisionManager = $container->get('test.autowiring_types.autowired_services')->getAccessDecisionManager();
$this->assertInstanceOf('Symfony\Component\Security\Core\Authorization\AccessDecisionManager', $accessDecisionManager);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a test-case where the debug variant is retrieved in debug/dev?

Copy link
Author

Choose a reason for hiding this comment

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

added, 2f6a92b.

}

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

$accessDecisionManager = $container->get('test.autowiring_types.autowired_services')->getAccessDecisionManager();
$this->assertInstanceOf('Symfony\Component\Security\Core\Authorization\AccessDecisionManager', $accessDecisionManager);
Copy link
Contributor

Choose a reason for hiding this comment

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

When in debug, it should be an instance of Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager

Copy link
Author

Choose a reason for hiding this comment

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

yes, this case exist in #19684 (targeted 3.1).

see #19684 (comment),

DebugAccessDecisionManager has been introduced in 3.1

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I thought this was a feature, nevertheless, good to have this test so we will notice it breaks in 3.1 and it can be fixed there.

I think it's correct that autowiring are allowed in lower versions, but I'm not sure. Following semver it would not be allowed because if you rely on the functionality and you go back 1 patch due to a bug fix bug, you also break this "feature".

}

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\SecurityBundle(),
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