Skip to content

Commit

Permalink
Move from deprecated SecurityContext to AuthorizationChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleMinotto committed Jun 16, 2016
1 parent 3373d12 commit b1ebbb3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<argument id="doctrine.orm.entity_manager" type="service"/>
</service>
<service class="%ae_feature.security.class%" id="ae_feature.security" public="false">
<argument id="security.context" type="service"/>
<argument id="security.authorization_checker" type="service"/>
</service>
<service class="%ae_feature.feature.class%" id="ae_feature.feature">
<argument id="ae_feature.manager" type="service"/>
Expand Down
8 changes: 4 additions & 4 deletions Security/FeatureSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ae\FeatureBundle\Security;

use Ae\FeatureBundle\Entity\Feature;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

/**
* Controls access to a Feature.
Expand All @@ -13,14 +13,14 @@
class FeatureSecurity
{
/**
* @param SecurityContextInterface|null
* @param AuthorizationCheckerInterface|null
*/
protected $context;

/**
* @param SecurityContextInterface $context
* @param AuthorizationCheckerInterface $context
*/
public function __construct(SecurityContextInterface $context = null)
public function __construct(AuthorizationCheckerInterface $context = null)
{
$this->context = $context;
}
Expand Down
7 changes: 4 additions & 3 deletions Tests/Security/FeatureSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Ae\FeatureBundle\Entity\Feature;
use Ae\FeatureBundle\Security\FeatureSecurity;
use PHPUnit_Framework_TestCase;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

/**
* @author Carlo Forghieri <carlo@adespresso.com>
Expand All @@ -18,10 +18,11 @@ class FeatureSecurityTest extends PHPUnit_Framework_TestCase
protected function setUp()
{
$context = $this
->getMockBuilder(SecurityContextInterface::class)
->getMockBuilder(AuthorizationCheckerInterface::class)
->disableOriginalConstructor()
->getMock();
$context->expects($this->any())
$context
->expects($this->any())
->method('isGranted')
->will($this->returnValueMap([
['ROLE_USER', null, true],
Expand Down
29 changes: 29 additions & 0 deletions Tests/Security/LegacyFeatureSecurityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Ae\FeatureBundle\Tests\Security;

use Ae\FeatureBundle\Security\FeatureSecurity;
use Symfony\Component\Security\Core\SecurityContextInterface;

/**
* @author Emanuele Minotto <emanuele@adespresso.com>
* @covers Ae\FeatureBundle\Security\FeatureSecurity
*/
class LegacyFeatureSecurityTest extends FeatureSecurityTest
{
protected function setUp()
{
$context = $this
->getMockBuilder(SecurityContextInterface::class)
->disableOriginalConstructor()
->getMock();
$context
->expects($this->any())
->method('isGranted')
->will($this->returnValueMap([
['ROLE_USER', null, true],
['ROLE_ADMIN', null, false],
]));
$this->security = new FeatureSecurity($context);
}
}

0 comments on commit b1ebbb3

Please sign in to comment.