diff options
Diffstat (limited to 'Core')
29 files changed, 19 insertions, 1117 deletions
diff --git a/Core/Authentication/SimpleFormAuthenticatorInterface.php b/Core/Authentication/SimpleFormAuthenticatorInterface.php deleted file mode 100644 index ae2b58b..0000000 --- a/Core/Authentication/SimpleFormAuthenticatorInterface.php +++ /dev/null @@ -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); -} diff --git a/Core/Authentication/SimplePreAuthenticatorInterface.php b/Core/Authentication/SimplePreAuthenticatorInterface.php deleted file mode 100644 index c01f064..0000000 --- a/Core/Authentication/SimplePreAuthenticatorInterface.php +++ /dev/null @@ -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); -} diff --git a/Core/Authentication/Token/AnonymousToken.php b/Core/Authentication/Token/AnonymousToken.php index 22fc611..e1dfef4 100644 --- a/Core/Authentication/Token/AnonymousToken.php +++ b/Core/Authentication/Token/AnonymousToken.php @@ -47,16 +47,6 @@ class AnonymousToken extends AbstractToken } /** - * @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. * * @return string diff --git a/Core/Authentication/Token/RememberMeToken.php b/Core/Authentication/Token/RememberMeToken.php index 60e36f2..edd77ab 100644 --- a/Core/Authentication/Token/RememberMeToken.php +++ b/Core/Authentication/Token/RememberMeToken.php @@ -74,16 +74,6 @@ class RememberMeToken extends AbstractToken } /** - * @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. * * @return string diff --git a/Core/Authorization/AccessDecisionManager.php b/Core/Authorization/AccessDecisionManager.php index 7cefef1..e40d906 100644 --- a/Core/Authorization/AccessDecisionManager.php +++ b/Core/Authorization/AccessDecisionManager.php @@ -73,38 +73,6 @@ class AccessDecisionManager implements AccessDecisionManagerInterface } /** - * {@inheritdoc} - */ - public function supportsAttribute($attribute) - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); - - foreach ($this->voters as $voter) { - if ($voter->supportsAttribute($attribute)) { - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); - - foreach ($this->voters as $voter) { - if ($voter->supportsClass($class)) { - return true; - } - } - - return false; - } - - /** * Grants access if any voter returns an affirmative response. * * If all voters abstained from voting, the decision will be based on the diff --git a/Core/Authorization/AccessDecisionManagerInterface.php b/Core/Authorization/AccessDecisionManagerInterface.php index d18b5e3..723ef19 100644 --- a/Core/Authorization/AccessDecisionManagerInterface.php +++ b/Core/Authorization/AccessDecisionManagerInterface.php @@ -30,26 +30,4 @@ interface AccessDecisionManagerInterface * @return bool true if the access is granted, false otherwise */ public function decide(TokenInterface $token, array $attributes, $object = null); - - /** - * Checks if the access decision manager supports the given attribute. - * - * @param string $attribute An attribute - * - * @return bool true if this decision manager supports the attribute, false otherwise - * - * @deprecated since version 2.8, to be removed in 3.0. - */ - public function supportsAttribute($attribute); - - /** - * Checks if the access decision manager supports the given class. - * - * @param string $class A class name - * - * @return true if this decision manager can process the class - * - * @deprecated since version 2.8, to be removed in 3.0. - */ - public function supportsClass($class); } diff --git a/Core/Authorization/Voter/AbstractVoter.php b/Core/Authorization/Voter/AbstractVoter.php index 7b04222..665d5f1 100644 --- a/Core/Authorization/Voter/AbstractVoter.php +++ b/Core/Authorization/Voter/AbstractVoter.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Security\Core\Authorization\Voter; -use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** @@ -22,32 +21,6 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; abstract class AbstractVoter implements VoterInterface { /** - * {@inheritdoc} - */ - public function supportsAttribute($attribute) - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); - - return in_array($attribute, $this->getSupportedAttributes()); - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); - - foreach ($this->getSupportedClasses() as $supportedClass) { - if ($supportedClass === $class || is_subclass_of($class, $supportedClass)) { - return true; - } - } - - return false; - } - - /** * Iteratively check all given attributes by calling isGranted. * * This method terminates as soon as it is able to return ACCESS_GRANTED @@ -89,98 +62,22 @@ abstract class AbstractVoter implements VoterInterface /** * Determines if the attribute and object are supported by this voter. * - * This method will become abstract in 3.0. - * * @param string $attribute An attribute * @param string $object The object to secure * * @return bool True if the attribute and object is supported, false otherwise */ - protected function supports($attribute, $object) - { - @trigger_error('The getSupportedClasses and getSupportedAttributes methods are deprecated since version 2.8 and will be removed in version 3.0. Overwrite supports instead.', E_USER_DEPRECATED); - - $classIsSupported = false; - foreach ($this->getSupportedClasses() as $supportedClass) { - if ($object instanceof $supportedClass) { - $classIsSupported = true; - break; - } - } - - if (!$classIsSupported) { - return false; - } - - if (!in_array($attribute, $this->getSupportedAttributes())) { - return false; - } - - return true; - } - - /** - * Return an array of supported classes. This will be called by supportsClass. - * - * @return array an array of supported classes, i.e. array('Acme\DemoBundle\Model\Product') - * - * @deprecated since version 2.8, to be removed in 3.0. Use supports() instead. - */ - protected function getSupportedClasses() - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); - } - - /** - * Return an array of supported attributes. This will be called by supportsAttribute. - * - * @return array an array of supported attributes, i.e. array('CREATE', 'READ') - * - * @deprecated since version 2.8, to be removed in 3.0. Use supports() instead. - */ - protected function getSupportedAttributes() - { - @trigger_error('The '.__METHOD__.' is deprecated since version 2.8 and will be removed in version 3.0.', E_USER_DEPRECATED); - } - - /** - * Perform a single access check operation on a given attribute, object and (optionally) user - * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass - * $user can be one of the following: - * a UserInterface object (fully authenticated user) - * a string (anonymously authenticated user). - * - * @param string $attribute - * @param object $object - * @param UserInterface|string $user - * - * @deprecated This method will be removed in 3.0 - override voteOnAttribute instead. - * - * @return bool - */ - protected function isGranted($attribute, $object, $user = null) - { - // forces isGranted() or voteOnAttribute() to be overridden - throw new \BadMethodCallException(sprintf('You must override the voteOnAttribute() method in "%s".', get_class($this))); - } + abstract protected function supports($attribute, $class); /** * Perform a single access check operation on a given attribute, object and token. * It is safe to assume that $attribute and $object's class pass supports method call. * - * This method will become abstract in 3.0. - * * @param string $attribute * @param object $object * @param TokenInterface $token * * @return bool */ - protected function voteOnAttribute($attribute, $object, TokenInterface $token) - { - // the user should override this method, and not rely on the deprecated isGranted() - @trigger_error(sprintf("The AbstractVoter::isGranted() method is deprecated since 2.8 and won't be called anymore in 3.0. Override voteOnAttribute() in %s instead.", get_class($this)), E_USER_DEPRECATED); - - return $this->isGranted($attribute, $object, $token->getUser()); - } + abstract protected function voteOnAttribute($attribute, $object, TokenInterface $token); } diff --git a/Core/Authorization/Voter/AuthenticatedVoter.php b/Core/Authorization/Voter/AuthenticatedVoter.php index 5847e0d..762e9bc 100644 --- a/Core/Authorization/Voter/AuthenticatedVoter.php +++ b/Core/Authorization/Voter/AuthenticatedVoter.php @@ -44,27 +44,13 @@ class AuthenticatedVoter implements VoterInterface /** * {@inheritdoc} */ - public function supportsAttribute($attribute) - { - return null !== $attribute && (self::IS_AUTHENTICATED_FULLY === $attribute || self::IS_AUTHENTICATED_REMEMBERED === $attribute || self::IS_AUTHENTICATED_ANONYMOUSLY === $attribute); - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - return true; - } - - /** - * {@inheritdoc} - */ public function vote(TokenInterface $token, $object, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN; foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { + if (null === $attribute || (self::IS_AUTHENTICATED_FULLY !== $attribute + && self::IS_AUTHENTICATED_REMEMBERED !== $attribute + && self::IS_AUTHENTICATED_ANONYMOUSLY !== $attribute)) { continue; } diff --git a/Core/Authorization/Voter/ExpressionVoter.php b/Core/Authorization/Voter/ExpressionVoter.php index 98b8f50..0842856 100644 --- a/Core/Authorization/Voter/ExpressionVoter.php +++ b/Core/Authorization/Voter/ExpressionVoter.php @@ -52,28 +52,12 @@ class ExpressionVoter implements VoterInterface /** * {@inheritdoc} */ - public function supportsAttribute($attribute) - { - return $attribute instanceof Expression; - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - return true; - } - - /** - * {@inheritdoc} - */ public function vote(TokenInterface $token, $object, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN; $variables = null; foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { + if (!$attribute instanceof Expression) { continue; } diff --git a/Core/Authorization/Voter/RoleVoter.php b/Core/Authorization/Voter/RoleVoter.php index 722675d..74e2363 100644 --- a/Core/Authorization/Voter/RoleVoter.php +++ b/Core/Authorization/Voter/RoleVoter.php @@ -35,29 +35,13 @@ class RoleVoter implements VoterInterface /** * {@inheritdoc} */ - public function supportsAttribute($attribute) - { - return 0 === strpos($attribute, $this->prefix); - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - return true; - } - - /** - * {@inheritdoc} - */ public function vote(TokenInterface $token, $object, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN; $roles = $this->extractRoles($token); foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { + if (0 !== strpos($attribute, $this->prefix)) { continue; } diff --git a/Core/Authorization/Voter/VoterInterface.php b/Core/Authorization/Voter/VoterInterface.php index 7e243f9..1697eaf 100644 --- a/Core/Authorization/Voter/VoterInterface.php +++ b/Core/Authorization/Voter/VoterInterface.php @@ -25,28 +25,6 @@ interface VoterInterface const ACCESS_DENIED = -1; /** - * Checks if the voter supports the given attribute. - * - * @param string $attribute An attribute - * - * @return bool true if this Voter supports the attribute, false otherwise - * - * @deprecated since version 2.8, to be removed in 3.0. - */ - public function supportsAttribute($attribute); - - /** - * Checks if the voter supports the given class. - * - * @param string $class A class name - * - * @return bool true if this Voter can process the class - * - * @deprecated since version 2.8, to be removed in 3.0. - */ - public function supportsClass($class); - - /** * Returns the vote for the given parameters. * * This method must return one of the following constants: diff --git a/Core/Encoder/BCryptPasswordEncoder.php b/Core/Encoder/BCryptPasswordEncoder.php index d2b0319..c0c8fe0 100644 --- a/Core/Encoder/BCryptPasswordEncoder.php +++ b/Core/Encoder/BCryptPasswordEncoder.php @@ -34,10 +34,6 @@ class BCryptPasswordEncoder extends BasePasswordEncoder */ public function __construct($cost) { - if (!function_exists('password_hash')) { - throw new \RuntimeException('To use the BCrypt encoder, you need to upgrade to PHP 5.5 or install the "ircmaxell/password-compat" via Composer.'); - } - $cost = (int) $cost; if ($cost < 4 || $cost > 31) { throw new \InvalidArgumentException('Cost must be in the range of 4-31.'); diff --git a/Core/Encoder/Pbkdf2PasswordEncoder.php b/Core/Encoder/Pbkdf2PasswordEncoder.php index 6f24c4f..8422a4b 100644 --- a/Core/Encoder/Pbkdf2PasswordEncoder.php +++ b/Core/Encoder/Pbkdf2PasswordEncoder.php @@ -64,11 +64,7 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm)); } - if (function_exists('hash_pbkdf2')) { - $digest = hash_pbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length, true); - } else { - $digest = $this->hashPbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length); - } + $digest = hash_pbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length, true); return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest); } @@ -80,24 +76,4 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder { return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt)); } - - private function hashPbkdf2($algorithm, $password, $salt, $iterations, $length = 0) - { - // Number of blocks needed to create the derived key - $blocks = ceil($length / strlen(hash($algorithm, null, true))); - $digest = ''; - - for ($i = 1; $i <= $blocks; ++$i) { - $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true); - - // Iterations - for ($j = 1; $j < $iterations; ++$j) { - $ib ^= ($block = hash_hmac($algorithm, $block, $password, true)); - } - - $digest .= $ib; - } - - return substr($digest, 0, $this->length); - } } diff --git a/Core/README.md b/Core/README.md index f1da5b1..3c6a117 100644 --- a/Core/README.md +++ b/Core/README.md @@ -11,7 +11,7 @@ Resources Documentation: -https://symfony.com/doc/2.8/book/security.html +https://symfony.com/doc/3.0/book/security.html Tests ----- diff --git a/Core/SecurityContext.php b/Core/SecurityContext.php deleted file mode 100644 index 027ff49..0000000 --- a/Core/SecurityContext.php +++ /dev/null @@ -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); - } -} diff --git a/Core/SecurityContextInterface.php b/Core/SecurityContextInterface.php deleted file mode 100644 index 2a06ca4..0000000 --- a/Core/SecurityContextInterface.php +++ /dev/null @@ -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; -} diff --git a/Core/Tests/Authorization/AccessDecisionManagerTest.php b/Core/Tests/Authorization/AccessDecisionManagerTest.php index 412af91..0e77c75 100644 --- a/Core/Tests/Authorization/AccessDecisionManagerTest.php +++ b/Core/Tests/Authorization/AccessDecisionManagerTest.php @@ -17,42 +17,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase { /** - * @group legacy - */ - public function testSupportsClass() - { - $manager = new AccessDecisionManager(array( - $this->getVoterSupportsClass(true), - $this->getVoterSupportsClass(false), - )); - $this->assertTrue($manager->supportsClass('FooClass')); - - $manager = new AccessDecisionManager(array( - $this->getVoterSupportsClass(false), - $this->getVoterSupportsClass(false), - )); - $this->assertFalse($manager->supportsClass('FooClass')); - } - - /** - * @group legacy - */ - public function testSupportsAttribute() - { - $manager = new AccessDecisionManager(array( - $this->getVoterSupportsAttribute(true), - $this->getVoterSupportsAttribute(false), - )); - $this->assertTrue($manager->supportsAttribute('foo')); - - $manager = new AccessDecisionManager(array( - $this->getVoterSupportsAttribute(false), - $this->getVoterSupportsAttribute(false), - )); - $this->assertFalse($manager->supportsAttribute('foo')); - } - - /** * @expectedException \InvalidArgumentException */ public function testSetUnsupportedStrategy() @@ -173,24 +137,4 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase return $voter; } - - protected function getVoterSupportsClass($ret) - { - $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface'); - $voter->expects($this->any()) - ->method('supportsClass') - ->will($this->returnValue($ret)); - - return $voter; - } - - protected function getVoterSupportsAttribute($ret) - { - $voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface'); - $voter->expects($this->any()) - ->method('supportsAttribute') - ->will($this->returnValue($ret)); - - return $voter; - } } diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php index 5ea7732..537dc4c 100644 --- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php +++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -54,27 +54,6 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); } - - /** - * @dataProvider getTests - * @group legacy - */ - public function testVoteLegacy(array $attributes, $expectedVote, $object, $message) - { - $voter = new AbstractVoterTest_LegacyVoter(); - - $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message); - } - - /** - * @group legacy - * @expectedException \BadMethodCallException - */ - public function testNoOverriddenMethodsThrowsException() - { - $voter = new AbstractVoterTest_NothingImplementedVoter(); - $voter->vote($this->token, new \stdClass(), array('EDIT')); - } } class AbstractVoterTest_Voter extends AbstractVoter @@ -89,36 +68,3 @@ class AbstractVoterTest_Voter extends AbstractVoter return $object instanceof \stdClass && in_array($attribute, array('EDIT', 'CREATE')); } } - -class AbstractVoterTest_LegacyVoter extends AbstractVoter -{ - protected function getSupportedClasses() - { - return array('stdClass'); - } - - protected function getSupportedAttributes() - { - return array('EDIT', 'CREATE'); - } - - protected function isGranted($attribute, $object, $user = null) - { - return 'EDIT' === $attribute; - } -} - -class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter -{ - protected function getSupportedClasses() - { - return array('stdClass'); - } - - protected function getSupportedAttributes() - { - return array('EDIT', 'CREATE'); - } - - // this is a bad voter that hasn't overridden isGranted or voteOnAttribute -} diff --git a/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php b/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php index 4679c0f..60e2a19 100644 --- a/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php +++ b/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php @@ -17,12 +17,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; class AuthenticatedVoterTest extends \PHPUnit_Framework_TestCase { - public function testSupportsClass() - { - $voter = new AuthenticatedVoter($this->getResolver()); - $this->assertTrue($voter->supportsClass('stdClass')); - } - /** * @dataProvider getVoteTests */ diff --git a/Core/Tests/Authorization/Voter/ExpressionVoterTest.php b/Core/Tests/Authorization/Voter/ExpressionVoterTest.php index dc8ea79..5296296 100644 --- a/Core/Tests/Authorization/Voter/ExpressionVoterTest.php +++ b/Core/Tests/Authorization/Voter/ExpressionVoterTest.php @@ -17,15 +17,6 @@ use Symfony\Component\Security\Core\Role\Role; class ExpressionVoterTest extends \PHPUnit_Framework_TestCase { - public function testSupportsAttribute() - { - $expression = $this->createExpression(); - $expressionLanguage = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage'); - $voter = new ExpressionVoter($expressionLanguage, $this->createTrustResolver(), $this->createRoleHierarchy()); - - $this->assertTrue($voter->supportsAttribute($expression)); - } - /** * @dataProvider getVoteTests */ diff --git a/Core/Tests/Authorization/Voter/RoleVoterTest.php b/Core/Tests/Authorization/Voter/RoleVoterTest.php index 03ab2da..9982bdf 100644 --- a/Core/Tests/Authorization/Voter/RoleVoterTest.php +++ b/Core/Tests/Authorization/Voter/RoleVoterTest.php @@ -17,13 +17,6 @@ use Symfony\Component\Security\Core\Role\Role; class RoleVoterTest extends \PHPUnit_Framework_TestCase { - public function testSupportsClass() - { - $voter = new RoleVoter(); - - $this->assertTrue($voter->supportsClass('Foo')); - } - /** * @dataProvider getVoteTests */ diff --git a/Core/Tests/LegacySecurityContextTest.php b/Core/Tests/LegacySecurityContextTest.php deleted file mode 100644 index 4502261..0000000 --- a/Core/Tests/LegacySecurityContextTest.php +++ /dev/null @@ -1,132 +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\Security; -use Symfony\Component\Security\Core\SecurityContext; -use Symfony\Component\Security\Core\SecurityContextInterface; - -/** - * @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), - ); - } - - /** - * 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); - } -} diff --git a/Core/Tests/Util/ClassUtilsTest.php b/Core/Tests/Util/ClassUtilsTest.php deleted file mode 100644 index b048206..0000000 --- a/Core/Tests/Util/ClassUtilsTest.php +++ /dev/null @@ -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 - { - } -} diff --git a/Core/Tests/Util/SecureRandomTest.php b/Core/Tests/Util/SecureRandomTest.php deleted file mode 100644 index a78d5a2..0000000 --- a/Core/Tests/Util/SecureRandomTest.php +++ /dev/null @@ -1,161 +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\SecureRandom; - -/** - * @group legacy - */ -class SecureRandomTest extends \PHPUnit_Framework_TestCase -{ - /** - * T1: Monobit test. - */ - public function testMonobit() - { - $secureRandom = new SecureRandom(); - $nbOnBits = substr_count($this->getBitSequence($secureRandom, 20000), '1'); - $this->assertTrue($nbOnBits > 9654 && $nbOnBits < 10346, 'Monobit test failed, number of turned on bits: '.$nbOnBits); - } - - /** - * T2: Chi-square test with 15 degrees of freedom (chi-Quadrat-Anpassungstest). - */ - public function testPoker() - { - $secureRandom = new SecureRandom(); - $b = $this->getBitSequence($secureRandom, 20000); - $c = array(); - for ($i = 0; $i <= 15; ++$i) { - $c[$i] = 0; - } - - for ($j = 1; $j <= 5000; ++$j) { - $k = 4 * $j - 1; - ++$c[8 * $b[$k - 3] + 4 * $b[$k - 2] + 2 * $b[$k - 1] + $b[$k]]; - } - - $f = 0; - for ($i = 0; $i <= 15; ++$i) { - $f += $c[$i] * $c[$i]; - } - - $Y = 16 / 5000 * $f - 5000; - - $this->assertTrue($Y > 1.03 && $Y < 57.4, 'Poker test failed, Y = '.$Y); - } - - /** - * Run test. - */ - public function testRun() - { - $secureRandom = new SecureRandom(); - $b = $this->getBitSequence($secureRandom, 20000); - - $runs = array(); - for ($i = 1; $i <= 6; ++$i) { - $runs[$i] = 0; - } - - $addRun = function ($run) use (&$runs) { - if ($run > 6) { - $run = 6; - } - - ++$runs[$run]; - }; - - $currentRun = 0; - $lastBit = null; - for ($i = 0; $i < 20000; ++$i) { - if ($lastBit === $b[$i]) { - ++$currentRun; - } else { - if ($currentRun > 0) { - $addRun($currentRun); - } - - $lastBit = $b[$i]; - $currentRun = 0; - } - } - if ($currentRun > 0) { - $addRun($currentRun); - } - - $this->assertTrue($runs[1] > 2267 && $runs[1] < 2733, 'Runs of length 1 outside of defined interval: '.$runs[1]); - $this->assertTrue($runs[2] > 1079 && $runs[2] < 1421, 'Runs of length 2 outside of defined interval: '.$runs[2]); - $this->assertTrue($runs[3] > 502 && $runs[3] < 748, 'Runs of length 3 outside of defined interval: '.$runs[3]); - $this->assertTrue($runs[4] > 233 && $runs[4] < 402, 'Runs of length 4 outside of defined interval: '.$runs[4]); - $this->assertTrue($runs[5] > 90 && $runs[5] < 223, 'Runs of length 5 outside of defined interval: '.$runs[5]); - $this->assertTrue($runs[6] > 90 && $runs[6] < 233, 'Runs of length 6 outside of defined interval: '.$runs[6]); - } - - /** - * Long-run test. - */ - public function testLongRun() - { - $secureRandom = new SecureRandom(); - $b = $this->getBitSequence($secureRandom, 20000); - - $longestRun = $currentRun = 0; - $lastBit = null; - for ($i = 0; $i < 20000; ++$i) { - if ($lastBit === $b[$i]) { - ++$currentRun; - } else { - if ($currentRun > $longestRun) { - $longestRun = $currentRun; - } - $lastBit = $b[$i]; - $currentRun = 0; - } - } - if ($currentRun > $longestRun) { - $longestRun = $currentRun; - } - - $this->assertTrue($longestRun < 34, 'Failed longest run test: '.$longestRun); - } - - /** - * Serial Correlation (Autokorrelationstest). - */ - public function testSerialCorrelation() - { - $secureRandom = new SecureRandom(); - $shift = mt_rand(1, 5000); - $b = $this->getBitSequence($secureRandom, 20000); - - $Z = 0; - for ($i = 0; $i < 5000; ++$i) { - $Z += $b[$i] === $b[$i + $shift] ? 1 : 0; - } - - $this->assertTrue($Z > 2326 && $Z < 2674, 'Failed serial correlation test: '.$Z); - } - - private function getBitSequence($secureRandom, $length) - { - $bitSequence = ''; - for ($i = 0; $i < $length; $i += 40) { - $value = unpack('H*', $secureRandom->nextBytes(5)); - $value = str_pad(base_convert($value[1], 16, 2), 40, '0', STR_PAD_LEFT); - $bitSequence .= $value; - } - - return substr($bitSequence, 0, $length); - } -} diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php deleted file mode 100644 index 8053732..0000000 --- a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php +++ /dev/null @@ -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; - } -} diff --git a/Core/Util/ClassUtils.php b/Core/Util/ClassUtils.php deleted file mode 100644 index 06186ef..0000000 --- a/Core/Util/ClassUtils.php +++ /dev/null @@ -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); - } -} diff --git a/Core/Util/SecureRandom.php b/Core/Util/SecureRandom.php deleted file mode 100644 index 06ed893..0000000 --- a/Core/Util/SecureRandom.php +++ /dev/null @@ -1,33 +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; - -@trigger_error('The '.__NAMESPACE__.'\SecureRandom class is deprecated since version 2.8 and will be removed in 3.0. Use the random_bytes() function instead.', E_USER_DEPRECATED); - -/** - * A secure random number generator implementation. - * - * @author Fabien Potencier <fabien@symfony.com> - * @author Johannes M. Schmitt <schmittjoh@gmail.com> - * - * @deprecated since version 2.8, to be removed in 3.0. Use the random_bytes function instead - */ -final class SecureRandom implements SecureRandomInterface -{ - /** - * {@inheritdoc} - */ - public function nextBytes($nbBytes) - { - return random_bytes($nbBytes); - } -} diff --git a/Core/Util/SecureRandomInterface.php b/Core/Util/SecureRandomInterface.php deleted file mode 100644 index df5509b..0000000 --- a/Core/Util/SecureRandomInterface.php +++ /dev/null @@ -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\Core\Util; - -/** - * Interface that needs to be implemented by all secure random number generators. - * - * @author Fabien Potencier <fabien@symfony.com> - * - * @deprecated since version 2.8, to be removed in 3.0. Use the random_bytes function instead - */ -interface SecureRandomInterface -{ - /** - * Generates the specified number of secure random bytes. - * - * @param int $nbBytes - * - * @return string - */ - public function nextBytes($nbBytes); -} diff --git a/Core/composer.json b/Core/composer.json index 31b4653..bc14d0a 100644 --- a/Core/composer.json +++ b/Core/composer.json @@ -16,26 +16,24 @@ } ], "require": { - "php": ">=5.3.9", + "php": ">=5.5.9", "paragonie/random_compat": "~1.0" }, "require-dev": { - "symfony/event-dispatcher": "~2.1|~3.0.0", - "symfony/expression-language": "~2.6|~3.0.0", - "symfony/http-foundation": "~2.4|~3.0.0", - "symfony/translation": "~2.0,>=2.0.5|~3.0.0", - "symfony/validator": "~2.5,>=2.5.5|~3.0.0", - "psr/log": "~1.0", - "ircmaxell/password-compat": "1.0.*", - "symfony/ldap": "~2.8|~3.0.0" + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/expression-language": "~2.8|~3.0", + "symfony/http-foundation": "~2.8|~3.0", + "symfony/translation": "~2.8|~3.0", + "symfony/validator": "~2.8|~3.0", + "symfony/ldap": "~2.8|~3.0", + "psr/log": "~1.0" }, "suggest": { "symfony/event-dispatcher": "", "symfony/http-foundation": "", "symfony/validator": "For using the user password constraint", "symfony/expression-language": "For using the expression voter", - "symfony/ldap": "For using LDAP integration", - "ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5" + "symfony/ldap": "For using LDAP integration" }, "autoload": { "psr-4": { "Symfony\\Component\\Security\\Core\\": "" } @@ -43,7 +41,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.8-dev" + "dev-master": "3.0-dev" } } } |