Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
removed features supporting legacy version of Symfony
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 21, 2016
1 parent f0e1e6d commit 48ed01e
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 123 deletions.
34 changes: 0 additions & 34 deletions DependencyInjection/Compiler/LegacyPass.php

This file was deleted.

7 changes: 3 additions & 4 deletions EventListener/SecurityListener.php
Expand Up @@ -19,7 +19,6 @@
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;

Expand All @@ -36,10 +35,10 @@ class SecurityListener implements EventSubscriberInterface
private $trustResolver;
private $roleHierarchy;

public function __construct(SecurityContextInterface $securityContext = null, ExpressionLanguage $language = null, AuthenticationTrustResolverInterface $trustResolver = null, RoleHierarchyInterface $roleHierarchy = null, TokenStorageInterface $tokenStorage = null, AuthorizationCheckerInterface $authChecker = null)
public function __construct(ExpressionLanguage $language = null, AuthenticationTrustResolverInterface $trustResolver = null, RoleHierarchyInterface $roleHierarchy = null, TokenStorageInterface $tokenStorage = null, AuthorizationCheckerInterface $authChecker = null)
{
$this->tokenStorage = $tokenStorage ?: $securityContext;
$this->authChecker = $authChecker ?: $securityContext;
$this->tokenStorage = $tokenStorage;
$this->authChecker = $authChecker;
$this->language = $language;
$this->trustResolver = $trustResolver;
$this->roleHierarchy = $roleHierarchy;
Expand Down
1 change: 0 additions & 1 deletion Resources/config/security.xml
Expand Up @@ -6,7 +6,6 @@

<services>
<service id="sensio_framework_extra.security.listener" class="Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener">
<argument type="service" id="security.context" on-invalid="null" />

This comment has been minimized.

Copy link
@kingmad

kingmad Nov 29, 2016

@fabpot could you backport it to ver. 3.0.x to be able to use it in Symfony 2.8?

<argument type="service" id="sensio_framework_extra.security.expression_language" on-invalid="null" />
<argument type="service" id="security.authentication.trust_resolver" on-invalid="null" />
<argument type="service" id="security.role_hierarchy" on-invalid="null" />
Expand Down
2 changes: 0 additions & 2 deletions SensioFrameworkExtraBundle.php
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddParamConverterPass;
use Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\LegacyPass;

/**
* SensioFrameworkExtraBundle.
Expand All @@ -28,6 +27,5 @@ public function build(ContainerBuilder $container)
parent::build($container);

$container->addCompilerPass(new AddParamConverterPass());
$container->addCompilerPass(new LegacyPass());
}
}
51 changes: 0 additions & 51 deletions Tests/DependencyInjection/SensioFrameworkExtraExtensionTest.php
Expand Up @@ -12,53 +12,13 @@
namespace Sensio\Bundle\FrameworkExtraBundle\Tests\DependencyInjection;

use Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension;
use Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\LegacyPass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

class SensioFrameworkExtraExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testLegacySecurityListener()
{
if (interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) {
$this->markTestSkipped();
}

$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
$loader->load('security.xml');
$r = new \ReflectionClass('Symfony\Bundle\SecurityBundle\SecurityBundle');
$loader = new XmlFileLoader($container, new FileLocator(dirname($r->getFileName()).'/Resources/config'));
$loader->load('security.xml');
$this->registerLegacyPass($container);
$container->compile();

$securityContext = $container->getDefinition('sensio_framework_extra.security.listener')->getArgument(0);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $securityContext);
}

public function testSecurityListener()
{
if (!interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) {
$this->markTestSkipped();
}

$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
$loader->load('security.xml');
$r = new \ReflectionClass('Symfony\Bundle\SecurityBundle\SecurityBundle');
$loader = new XmlFileLoader($container, new FileLocator(dirname($r->getFileName()).'/Resources/config'));
$loader->load('security.xml');
$this->registerLegacyPass($container);
$container->compile();

$this->assertNull($container->getDefinition('sensio_framework_extra.security.listener')->getArgument(0));
}

public function testDefaultExpressionLanguageConfig()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -107,15 +67,4 @@ private function assertAlias(ContainerBuilder $container, $value, $key)
{
$this->assertEquals($value, (string) $container->getAlias($key), sprintf('%s alias is correct', $key));
}

private function registerLegacyPass(ContainerBuilder $container)
{
$passConfig = $container->getCompiler()->getPassConfig();
$passConfig->setAfterRemovingPasses(array());
$passConfig->setBeforeOptimizationPasses(array());
$passConfig->setBeforeRemovingPasses(array());
$passConfig->setOptimizationPasses(array());
$passConfig->setRemovingPasses(array());
$container->addCompilerPass(new LegacyPass());
}
}
32 changes: 1 addition & 31 deletions Tests/EventListener/SecurityListenerTest.php
Expand Up @@ -21,36 +21,6 @@

class SecurityListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
*/
public function testLegacyAccessDenied()
{
if (!interface_exists('Symfony\Component\Security\Core\SecurityContextInterface')) {
$this->markTestSkipped();
}

$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$token->expects($this->once())->method('getRoles')->will($this->returnValue(array()));

$securityContext = $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContextInterface')->getMock();
$securityContext->expects($this->once())->method('isGranted')->will($this->throwException(new AccessDeniedException()));
$securityContext->expects($this->exactly(2))->method('getToken')->will($this->returnValue($token));

$trustResolver = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface')->getMock();

$language = new ExpressionLanguage();

$listener = new SecurityListener($securityContext, $language, $trustResolver);
$request = $this->createRequest(new Security(array('expression' => 'has_role("ROLE_ADMIN") or is_granted("FOO")')));

$event = new FilterControllerEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), function () { return new Response(); }, $request, null);

$listener->onKernelController($event);
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
*/
Expand All @@ -73,7 +43,7 @@ public function testAccessDenied()

$language = new ExpressionLanguage();

$listener = new SecurityListener(null, $language, $trustResolver, null, $tokenStorage, $authChecker);
$listener = new SecurityListener($language, $trustResolver, null, $tokenStorage, $authChecker);
$request = $this->createRequest(new Security(array('expression' => 'has_role("ROLE_ADMIN") or is_granted("FOO")')));

$event = new FilterControllerEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), function () { return new Response(); }, $request, null);
Expand Down

0 comments on commit 48ed01e

Please sign in to comment.