[Security] Remove deprecated interfaces

This commit is contained in:
Nicolas Grekas 2015-09-03 21:29:24 +02:00
parent eca45b7624
commit 09ee344b05
19 changed files with 17 additions and 543 deletions

View File

@ -40,24 +40,6 @@ class SecurityDataCollectorTest extends \PHPUnit_Framework_TestCase
$this->assertEmpty($collector->getUser()); $this->assertEmpty($collector->getUser());
} }
/**
* @group legacy
*/
public function testLegacyCollectWhenAuthenticationTokenIsNull()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
$collector = new SecurityDataCollector($tokenStorage, $this->getRoleHierarchy());
$collector->collect($this->getRequest(), $this->getResponse());
$this->assertTrue($collector->isEnabled());
$this->assertFalse($collector->isAuthenticated());
$this->assertNull($collector->getTokenClass());
$this->assertTrue($collector->supportsRoleHierarchy());
$this->assertCount(0, $collector->getRoles());
$this->assertCount(0, $collector->getInheritedRoles());
$this->assertEmpty($collector->getUser());
}
/** @dataProvider provideRoles */ /** @dataProvider provideRoles */
public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles, array $inheritedRoles) public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles, array $inheritedRoles)
{ {

View File

@ -1,6 +1,11 @@
CHANGELOG CHANGELOG
========= =========
3.0.0
-----
* removed all deprecated codes from 2.x versions
2.8.0 2.8.0
----- -----

View File

@ -1,24 +0,0 @@
<?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\Component\Security\Core\Authentication;
use Symfony\Component\HttpFoundation\Request;
/**
* @deprecated Deprecated since version 2.8, to be removed in 3.0. Use the same interface from Security\Http\Authentication instead.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SimpleFormAuthenticatorInterface extends SimpleAuthenticatorInterface
{
public function createToken(Request $request, $username, $password, $providerKey);
}

View File

@ -1,24 +0,0 @@
<?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\Component\Security\Core\Authentication;
use Symfony\Component\HttpFoundation\Request;
/**
* @deprecated Since version 2.8, to be removed in 3.0. Use the same interface from Security\Http\Authentication instead.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface SimplePreAuthenticatorInterface extends SimpleAuthenticatorInterface
{
public function createToken(Request $request, $providerKey);
}

View File

@ -46,16 +46,6 @@ class AnonymousToken extends AbstractToken
return ''; return '';
} }
/**
* @deprecated Since version 2.8, to be removed in 3.0. Use getSecret() instead.
*/
public function getKey()
{
@trigger_error(__method__.'() is deprecated since version 2.8 and will be removed in 3.0. Use getSecret() instead.', E_USER_DEPRECATED);
return $this->getSecret();
}
/** /**
* Returns the secret. * Returns the secret.
* *

View File

@ -73,16 +73,6 @@ class RememberMeToken extends AbstractToken
return $this->providerKey; return $this->providerKey;
} }
/**
* @deprecated Since version 2.8, to be removed in 3.0. Use getSecret() instead.
*/
public function getKey()
{
@trigger_error(__method__.'() is deprecated since version 2.8 and will be removed in 3.0. Use getSecret() instead.', E_USER_DEPRECATED);
return $this->getSecret();
}
/** /**
* Returns the secret. * Returns the secret.
* *

View File

@ -1,104 +0,0 @@
<?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\Component\Security\Core;
@trigger_error('The '.__NAMESPACE__.'\SecurityContext class is deprecated since version 2.6 and will be removed in 3.0. Use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage or Symfony\Component\Security\Core\Authorization\AuthorizationChecker instead.', E_USER_DEPRECATED);
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* SecurityContext is the main entry point of the Security component.
*
* It gives access to the token representing the current user authentication.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @deprecated since version 2.6, to be removed in 3.0.
*/
class SecurityContext implements SecurityContextInterface
{
/**
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
* @var AuthorizationCheckerInterface
*/
private $authorizationChecker;
/**
* For backwards compatibility, the signature of sf <2.6 still works.
*
* @param TokenStorageInterface|AuthenticationManagerInterface $tokenStorage
* @param AuthorizationCheckerInterface|AccessDecisionManagerInterface $authorizationChecker
* @param bool $alwaysAuthenticate only applicable with old signature
*/
public function __construct($tokenStorage, $authorizationChecker, $alwaysAuthenticate = false)
{
$oldSignature = $tokenStorage instanceof AuthenticationManagerInterface && $authorizationChecker instanceof AccessDecisionManagerInterface;
$newSignature = $tokenStorage instanceof TokenStorageInterface && $authorizationChecker instanceof AuthorizationCheckerInterface;
// confirm possible signatures
if (!$oldSignature && !$newSignature) {
throw new \BadMethodCallException('Unable to construct SecurityContext, please provide the correct arguments');
}
if ($oldSignature) {
// renamed for clarity
$authenticationManager = $tokenStorage;
$accessDecisionManager = $authorizationChecker;
$tokenStorage = new TokenStorage();
$authorizationChecker = new AuthorizationChecker($tokenStorage, $authenticationManager, $accessDecisionManager, $alwaysAuthenticate);
}
$this->tokenStorage = $tokenStorage;
$this->authorizationChecker = $authorizationChecker;
}
/**
* @deprecated since version 2.6, to be removed in 3.0. Use TokenStorageInterface::getToken() instead.
*
* {@inheritdoc}
*/
public function getToken()
{
return $this->tokenStorage->getToken();
}
/**
* @deprecated since version 2.6, to be removed in 3.0. Use TokenStorageInterface::setToken() instead.
*
* {@inheritdoc}
*/
public function setToken(TokenInterface $token = null)
{
return $this->tokenStorage->setToken($token);
}
/**
* @deprecated since version 2.6, to be removed in 3.0. Use AuthorizationCheckerInterface::isGranted() instead.
*
* {@inheritdoc}
*/
public function isGranted($attributes, $object = null)
{
return $this->authorizationChecker->isGranted($attributes, $object);
}
}

View File

@ -1,29 +0,0 @@
<?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\Component\Security\Core;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* The SecurityContextInterface.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @deprecated since version 2.6, to be removed in 3.0.
*/
interface SecurityContextInterface extends TokenStorageInterface, AuthorizationCheckerInterface
{
const ACCESS_DENIED_ERROR = Security::ACCESS_DENIED_ERROR;
const AUTHENTICATION_ERROR = Security::AUTHENTICATION_ERROR;
const LAST_USERNAME = Security::LAST_USERNAME;
}

View File

@ -1,122 +0,0 @@
<?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\Component\Security\Core\Tests;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\SecurityContext;
/**
* @group legacy
*/
class LegacySecurityContextTest extends \PHPUnit_Framework_TestCase
{
private $tokenStorage;
private $authorizationChecker;
private $securityContext;
protected function setUp()
{
$this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$this->authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
$this->securityContext = new SecurityContext($this->tokenStorage, $this->authorizationChecker);
}
public function testGetTokenDelegation()
{
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$this->tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue($token));
$this->assertTrue($token === $this->securityContext->getToken());
}
public function testSetTokenDelegation()
{
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$this->tokenStorage
->expects($this->once())
->method('setToken')
->with($token);
$this->securityContext->setToken($token);
}
/**
* @dataProvider isGrantedDelegationProvider
*/
public function testIsGrantedDelegation($attributes, $object, $return)
{
$this->authorizationChecker
->expects($this->once())
->method('isGranted')
->with($attributes, $object)
->will($this->returnValue($return));
$this->assertEquals($return, $this->securityContext->isGranted($attributes, $object));
}
public function isGrantedDelegationProvider()
{
return array(
array(array(), new \stdClass(), true),
array(array('henk'), new \stdClass(), false),
array(null, new \stdClass(), false),
array('henk', null, true),
array(array(1), 'henk', true),
);
}
/**
* Test dedicated to check if the backwards compatibility is still working.
*/
public function testOldConstructorSignature()
{
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
new SecurityContext($authenticationManager, $accessDecisionManager);
}
/**
* @dataProvider oldConstructorSignatureFailuresProvider
* @expectedException \BadMethodCallException
*/
public function testOldConstructorSignatureFailures($first, $second)
{
new SecurityContext($first, $second);
}
public function oldConstructorSignatureFailuresProvider()
{
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
$authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
$accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
return array(
array(new \stdClass(), new \stdClass()),
array($tokenStorage, $accessDecisionManager),
array($accessDecisionManager, $tokenStorage),
array($authorizationChecker, $accessDecisionManager),
array($accessDecisionManager, $authorizationChecker),
array($tokenStorage, $accessDecisionManager),
array($authenticationManager, $authorizationChecker),
array('henk', 'hans'),
array(null, false),
array(true, null),
);
}
}

View File

@ -1,53 +0,0 @@
<?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\Component\Security\Core\Tests\Util
{
use Symfony\Component\Security\Core\Util\ClassUtils;
/**
* @group legacy
*/
class ClassUtilsTest extends \PHPUnit_Framework_TestCase
{
public static function dataGetClass()
{
return array(
array('stdClass', 'stdClass'),
array('Symfony\Component\Security\Core\Util\ClassUtils', 'Symfony\Component\Security\Core\Util\ClassUtils'),
array('MyProject\Proxies\__CG__\stdClass', 'stdClass'),
array('MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass', 'stdClass'),
array('MyProject\Proxies\__CG__\Symfony\Component\Security\Core\Tests\Util\ChildObject', 'Symfony\Component\Security\Core\Tests\Util\ChildObject'),
array(new TestObject(), 'Symfony\Component\Security\Core\Tests\Util\TestObject'),
array(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Core\Tests\Util\TestObject(), 'Symfony\Component\Security\Core\Tests\Util\TestObject'),
);
}
/**
* @dataProvider dataGetClass
*/
public function testGetRealClass($object, $expectedClassName)
{
$this->assertEquals($expectedClassName, ClassUtils::getRealClass($object));
}
}
class TestObject
{
}
}
namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Core\Tests\Util
{
class TestObject extends \Symfony\Component\Security\Core\Tests\Util\TestObject
{
}
}

View File

@ -1,28 +0,0 @@
<?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\Component\Security\Core\Tests\Validator\Constraints;
use Symfony\Component\Validator\Validation;
/**
* @since 2.5.4
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @group legacy
*/
class LegacyUserPasswordValidatorTest extends UserPasswordValidatorTest
{
protected function getApiVersion()
{
return Validation::API_VERSION_2_5_BC;
}
}

View File

@ -1,72 +0,0 @@
<?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\Component\Security\Core\Util;
use Symfony\Component\Security\Acl\Util\ClassUtils as AclClassUtils;
@trigger_error('The '.__NAMESPACE__.'\ClassUtils class is deprecated since version 2.8, to be removed in 3.0. Use Symfony\Component\Security\Acl\Util\ClassUtils instead.', E_USER_DEPRECATED);
/**
* Class related functionality for objects that
* might or might not be proxy objects at the moment.
*
* @deprecated ClassUtils is deprecated since version 2.8, to be removed in 3.0. Use Acl ClassUtils instead.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Johannes Schmitt <schmittjoh@gmail.com>
*/
class ClassUtils
{
/**
* Marker for Proxy class names.
*
* @var string
*/
const MARKER = '__CG__';
/**
* Length of the proxy marker.
*
* @var int
*/
const MARKER_LENGTH = 6;
/**
* This class should not be instantiated.
*/
private function __construct()
{
}
/**
* Gets the real class name of a class name that could be a proxy.
*
* @param string|object $object
*
* @return string
*/
public static function getRealClass($object)
{
if (class_exists('Symfony\Component\Security\Acl\Util\ClassUtils')) {
return AclClassUtils::getRealClass($object);
}
// fallback in case security-acl is not installed
$class = is_object($object) ? get_class($object) : $object;
if (false === $pos = strrpos($class, '\\'.self::MARKER.'\\')) {
return $class;
}
return substr($class, $pos + self::MARKER_LENGTH + 2);
}
}

View File

@ -11,11 +11,13 @@
namespace Symfony\Component\Security\Http\Authentication; namespace Symfony\Component\Security\Http\Authentication;
use Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface as BaseSimpleFormAuthenticatorInterface; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
interface SimpleFormAuthenticatorInterface extends BaseSimpleFormAuthenticatorInterface interface SimpleFormAuthenticatorInterface extends SimpleAuthenticatorInterface
{ {
public function createToken(Request $request, $username, $password, $providerKey);
} }

View File

@ -11,11 +11,13 @@
namespace Symfony\Component\Security\Http\Authentication; namespace Symfony\Component\Security\Http\Authentication;
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface as BaseSimplePreAuthenticatorInterface; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
interface SimplePreAuthenticatorInterface extends BaseSimplePreAuthenticatorInterface interface SimplePreAuthenticatorInterface extends SimpleAuthenticatorInterface
{ {
public function createToken(Request $request, $providerKey);
} }

View File

@ -22,7 +22,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface; use Symfony\Component\Security\Http\Authentication\SimpleFormAuthenticatorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\HttpUtils; use Symfony\Component\Security\Http\HttpUtils;

View File

@ -15,7 +15,7 @@ use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterfac
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface; use Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\AuthenticationException;

View File

@ -80,16 +80,6 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface
return $this->options['remember_me_parameter']; return $this->options['remember_me_parameter'];
} }
/**
* @deprecated Since version 2.8, to be removed in 3.0. Use getSecret() instead.
*/
public function getKey()
{
@trigger_error(__method__.'() is deprecated since version 2.8 and will be removed in 3.0. Use getSecret() instead.', E_USER_DEPRECATED);
return $this->getSecret();
}
/** /**
* @return string * @return string
*/ */

View File

@ -42,7 +42,7 @@ class SimplePreAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->token)) ->will($this->returnValue($this->token))
; ;
$simpleAuthenticator = $this->getMock('Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface'); $simpleAuthenticator = $this->getMock('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface');
$simpleAuthenticator $simpleAuthenticator
->expects($this->once()) ->expects($this->once())
->method('createToken') ->method('createToken')
@ -79,7 +79,7 @@ class SimplePreAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo(null)) ->with($this->equalTo(null))
; ;
$simpleAuthenticator = $this->getMock('Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface'); $simpleAuthenticator = $this->getMock('Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface');
$simpleAuthenticator $simpleAuthenticator
->expects($this->once()) ->expects($this->once())
->method('createToken') ->method('createToken')

View File

@ -1,31 +0,0 @@
<?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\Component\Security\Tests\Core;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Security;
/**
* @group legacy
*/
class LegacySecurityContextInterfaceTest extends \PHPUnit_Framework_TestCase
{
/**
* Test if the BC Layer is working as intended.
*/
public function testConstantSync()
{
$this->assertSame(Security::ACCESS_DENIED_ERROR, SecurityContextInterface::ACCESS_DENIED_ERROR);
$this->assertSame(Security::AUTHENTICATION_ERROR, SecurityContextInterface::AUTHENTICATION_ERROR);
$this->assertSame(Security::LAST_USERNAME, SecurityContextInterface::LAST_USERNAME);
}
}