Skip to content

Commit

Permalink
Merge branch 'feature/symfony3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bytehead committed Dec 15, 2016
2 parents 8785286 + 8563c4a commit ed13dd2
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 40 deletions.
21 changes: 15 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ php:
- 5.4
- 5.5
- 5.6
- 7.0

env:
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.4.*
- SYMFONY_VERSION=2.5.*
- SYMFONY_VERSION=2.6.*
- SYMFONY_VERSION=2.7.*
- SYMFONY_VERSION=2.8.*
- SYMFONY_VERSION=3.0.*

matrix:
exclude:
- php: 5.3
env: SYMFONY_VERSION=3.0.*
- php: 5.4
env: SYMFONY_VERSION=3.0.*

before_script:
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
- composer require symfony/security-bundle:${SYMFONY_VERSION} --prefer-source
- composer install --dev --prefer-source
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update --prefer-source
- composer require symfony/http-kernel:${SYMFONY_VERSION} --no-update --prefer-source
- composer require symfony/security-bundle:${SYMFONY_VERSION} --no-update --prefer-source
- composer require symfony/security-acl:${SYMFONY_VERSION} --no-update --prefer-source
- composer install --dev --prefer-source
15 changes: 15 additions & 0 deletions DependencyInjection/Compiler/OverrideServiceCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Oneup\AclBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class OverrideServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('security.acl.dbal.provider');
$definition->setClass('Oneup\AclBundle\Security\Authorization\Acl\AclProvider');
}
}
7 changes: 6 additions & 1 deletion DependencyInjection/OneupAclExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;

class OneupAclExtension extends Extension
Expand All @@ -16,7 +17,11 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
if (Kernel::VERSION_ID < 20600) {
$loader->load('manager_23.xml');
} else {
$loader->load('manager_26.xml');
}
$loader->load('security.xml');
$loader->load('driver.xml');
$loader->load('doctrine.xml');
Expand Down
2 changes: 2 additions & 0 deletions OneupAclBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Oneup\AclBundle\DependencyInjection\Compiler\MetaDataCompilerPass;
use Oneup\AclBundle\DependencyInjection\Compiler\OverrideServiceCompilerPass;

class OneupAclBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new OverrideServiceCompilerPass());
$container->addCompilerPass(new MetaDataCompilerPass());
}
}
17 changes: 17 additions & 0 deletions Resources/config/manager_23.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="https://symfony.com/schema/dic/services"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="oneup_acl.manager" class="%oneup_acl.manager.class%">
<argument type="service" id="security.acl.provider" />
<argument type="service" id="security.context" />
<argument type="service" id="security.context" />
<argument type="service" id="security.acl.object_identity_retrieval_strategy" />
<argument type="service" id="security.acl.collection_cache" />
<argument>%oneup_acl.permission_strategy%</argument>
</service>
</services>
</container>
17 changes: 17 additions & 0 deletions Resources/config/manager_26.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="https://symfony.com/schema/dic/services"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="oneup_acl.manager" class="%oneup_acl.manager.class%">
<argument type="service" id="security.acl.provider" />
<argument type="service" id="security.token_storage" />
<argument type="service" id="security.authorization_checker" />
<argument type="service" id="security.acl.object_identity_retrieval_strategy" />
<argument type="service" id="security.acl.collection_cache" />
<argument>%oneup_acl.permission_strategy%</argument>
</service>
</services>
</container>
10 changes: 1 addition & 9 deletions Resources/config/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@
</parameters>

<services>
<service id="oneup_acl.manager" class="%oneup_acl.manager.class%">
<argument type="service" id="security.acl.provider" />
<argument type="service" id="security.context" />
<argument type="service" id="security.acl.object_identity_retrieval_strategy" />
<argument type="service" id="security.acl.collection_cache" />
<argument>%oneup_acl.permission_strategy%</argument>
</service>

<service id="security.acl.collection_cache" class="%security.acl.collection_cache.class%">
<service id="security.acl.collection_cache" class="Symfony\Component\Security\Acl\Domain\AclCollectionCache">
<argument type="service" id="security.acl.provider" />
<argument type="service" id="security.acl.object_identity_retrieval_strategy" />
<argument type="service" id="security.acl.security_identity_retrieval_strategy" />
Expand Down
10 changes: 0 additions & 10 deletions Resources/config/services.xml

This file was deleted.

19 changes: 13 additions & 6 deletions Security/Acl/Manager/AclManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
use Symfony\Component\Security\Acl\Domain\AclCollectionCache;
use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

use Oneup\AclBundle\Security\Acl\Model\AbstractAclManager;

class AclManager extends AbstractAclManager
{
protected $cache;
protected $provider;
protected $context;
protected $token_storage;
protected $authorization_checker;
protected $objectIdentityStrategy;
protected $permissionStrategy;

public function __construct(
MutableAclProviderInterface $provider,
SecurityContextInterface $context,
$token_storage,
$authorization_checker,
ObjectIdentityRetrievalStrategyInterface $objectIdentityStrategy,
AclCollectionCache $cache,
$permissionStrategy
) {
$this->provider = $provider;
$this->context = $context;
$this->token_storage = $token_storage;
$this->authorization_checker = $authorization_checker;
$this->objectIdentityStrategy = $objectIdentityStrategy;
$this->cache = $cache;
$this->permissionStrategy = $permissionStrategy;
Expand All @@ -48,9 +50,14 @@ protected function getProvider()
return $this->provider;
}

protected function getSecurityContext()
protected function getTokenStorage()
{
return $this->context;
return $this->token_storage;
}

protected function getAuthorizationChecker()
{
return $this->authorization_checker;
}

protected function getObjectIdentityStrategy()
Expand Down
7 changes: 4 additions & 3 deletions Security/Acl/Model/AbstractAclManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
abstract class AbstractAclManager implements AclManagerInterface
{
abstract protected function getProvider();
abstract protected function getSecurityContext();
abstract protected function getTokenStorage();
abstract protected function getAuthorizationChecker();
abstract protected function getObjectIdentityStrategy();
abstract protected function getPermissionStrategy();

Expand Down Expand Up @@ -280,7 +281,7 @@ public function isGranted($attributes, $object = null, $field = null)
$object = new FieldVote($oid, $field);
}

return $this->getSecurityContext()->isGranted($attributes, $object);
return $this->getAuthorizationChecker()->isGranted($attributes, $object);
}

protected function revokePermissions($object, $identity)
Expand Down Expand Up @@ -488,7 +489,7 @@ protected function createObjectIdentity($object)

protected function getCurrentAuthenticationToken()
{
$token = $this->getSecurityContext()->getToken();
$token = $this->getTokenStorage()->getToken();

if (null === $token) {
return null;
Expand Down
5 changes: 3 additions & 2 deletions Tests/Model/AbstractSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
use Symfony\Component\HttpKernel\Kernel;

abstract class AbstractSecurityTest extends WebTestCase
{
Expand All @@ -24,7 +25,7 @@ protected function setUp()
$this->container = $this->client->getContainer();

$this->token = $this->createToken();
$this->container->get('security.context')->setToken($this->token);
$this->container->get((Kernel::VERSION_ID < 20600 ? 'security.context' : 'security.token_storage'))->setToken($this->token);

$this->connection = $this->container->get('database_connection');

Expand Down Expand Up @@ -94,7 +95,7 @@ public function testIfContainerExists()

public function testIfSecurityContextLoads()
{
$aclProvider = $this->container->get('security.context');
$aclProvider = $this->container->get((Kernel::VERSION_ID < 20600 ? 'security.context' : 'security.authorization_checker'));
$this->assertTrue($aclProvider->isGranted('ROLE_USER'));
$this->assertFalse($aclProvider->isGranted('ROLE_ADMIN'));
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/Security/Acl/Manager/AclManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Oneup\AclBundle\Tests\Security\Acl\Manager;

use Oneup\AclBundle\Tests\Model\AbstractSecurityTest;
use Symfony\Component\HttpKernel\Kernel;

class AclManagerTest extends AbstractSecurityTest
{
Expand All @@ -28,7 +29,7 @@ public function testIfTokenIsGrantedByGroup()
$this->assertFalse($this->manager->isGranted('EDIT', $this->object1));

// set token to admin token and try again
$this->container->get('security.context')->setToken($adminToken);
$this->container->get((Kernel::VERSION_ID < 20600 ? 'security.context' : 'security.token_storage'))->setToken($adminToken);
$this->assertTrue($this->manager->isGranted('VIEW', $this->object1));
$this->assertTrue($this->manager->isGranted('CREATE', $this->object1));
$this->assertTrue($this->manager->isGranted('EDIT', $this->object1));
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"symfony/framework-bundle": ">=2.2",
"symfony/security-bundle": ">=2.2",
"symfony/expression-language": "~2.4",
"symfony/expression-language": ">=2.4",
"doctrine/doctrine-bundle": "~1.2",
"doctrine/common": "~2.2",
"doctrine/dbal": "~2.2"
Expand All @@ -32,7 +32,7 @@
"require-dev": {
"symfony/finder": ">=2.0.16,<2.4-dev",
"symfony/browser-kit": "2.*",
"sensio/framework-extra-bundle": "~2.2",
"sensio/framework-extra-bundle": "~2.2|~3.0",
"doctrine/orm": "~2.4",
"phpunit/phpunit": "3.7.*"
},
Expand Down

0 comments on commit ed13dd2

Please sign in to comment.