diff options
Diffstat (limited to 'Core')
-rw-r--r-- | Core/Authentication/AuthenticationProviderManager.php | 6 | ||||
-rw-r--r-- | Core/README.md | 2 | ||||
-rw-r--r-- | Core/SecurityContext.php | 10 | ||||
-rw-r--r-- | Core/SecurityContextInterface.php | 4 | ||||
-rw-r--r-- | Core/Tests/Authentication/AuthenticationProviderManagerTest.php | 10 | ||||
-rw-r--r-- | Core/Tests/Encoder/BCryptPasswordEncoderTest.php | 11 | ||||
-rw-r--r-- | Core/Tests/LegacySecurityContextTest.php (renamed from Core/Tests/SecurityContextTest.php) | 7 | ||||
-rw-r--r-- | Core/Tests/User/UserTest.php | 9 | ||||
-rw-r--r-- | Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php | 27 | ||||
-rw-r--r-- | Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php | 16 | ||||
-rw-r--r-- | Core/User/User.php | 5 | ||||
-rw-r--r-- | Core/Util/SecureRandom.php | 4 | ||||
-rw-r--r-- | Core/Validator/Constraints/UserPasswordValidator.php | 10 | ||||
-rw-r--r-- | Core/composer.json | 7 | ||||
-rw-r--r-- | Core/phpunit.xml.dist | 1 |
15 files changed, 67 insertions, 62 deletions
diff --git a/Core/Authentication/AuthenticationProviderManager.php b/Core/Authentication/AuthenticationProviderManager.php index f713e8f..16de8da 100644 --- a/Core/Authentication/AuthenticationProviderManager.php +++ b/Core/Authentication/AuthenticationProviderManager.php @@ -48,6 +48,12 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface throw new \InvalidArgumentException('You must at least add one authentication provider.'); } + foreach ($providers as $provider) { + if (!$provider instanceof AuthenticationProviderInterface) { + throw new \InvalidArgumentException(sprintf('Provider "%s" must implement the AuthenticationProviderInterface.', get_class($provider))); + } + } + $this->providers = $providers; $this->eraseCredentials = (bool) $eraseCredentials; } diff --git a/Core/README.md b/Core/README.md index 73e3e85..b0d1749 100644 --- a/Core/README.md +++ b/Core/README.md @@ -11,7 +11,7 @@ Resources Documentation: -https://symfony.com/doc/2.6/book/security.html +https://symfony.com/doc/2.7/book/security.html Tests ----- diff --git a/Core/SecurityContext.php b/Core/SecurityContext.php index 0761c59..8bcbfee 100644 --- a/Core/SecurityContext.php +++ b/Core/SecurityContext.php @@ -11,6 +11,8 @@ 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; @@ -26,7 +28,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; * * @author Fabien Potencier <fabien@symfony.com> * @author Johannes M. Schmitt <schmittjoh@gmail.com> - * @deprecated Deprecated since version 2.6, to be removed in 3.0. + * @deprecated since version 2.6, to be removed in 3.0. */ class SecurityContext implements SecurityContextInterface { @@ -70,6 +72,8 @@ class SecurityContext implements SecurityContextInterface } /** + * @deprecated since version 2.6, to be removed in 3.0. Use TokenStorageInterface::getToken() instead. + * * {@inheritdoc} */ public function getToken() @@ -78,6 +82,8 @@ class SecurityContext implements SecurityContextInterface } /** + * @deprecated since version 2.6, to be removed in 3.0. Use TokenStorageInterface::setToken() instead. + * * {@inheritdoc} */ public function setToken(TokenInterface $token = null) @@ -86,6 +92,8 @@ class SecurityContext implements SecurityContextInterface } /** + * @deprecated since version 2.6, to be removed in 3.0. Use AuthorizationCheckerInterface::isGranted() instead. + * * {@inheritdoc} */ public function isGranted($attributes, $object = null) diff --git a/Core/SecurityContextInterface.php b/Core/SecurityContextInterface.php index bceb506..61cdf4f 100644 --- a/Core/SecurityContextInterface.php +++ b/Core/SecurityContextInterface.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Core; +@trigger_error('The '.__NAMESPACE__.'\SecurityContextInterface interface is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); + use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -18,7 +20,7 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; * The SecurityContextInterface. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> - * @deprecated Deprecated since version 2.6, to be removed in 3.0. + * @deprecated since version 2.6, to be removed in 3.0. */ interface SecurityContextInterface extends TokenStorageInterface, AuthorizationCheckerInterface { diff --git a/Core/Tests/Authentication/AuthenticationProviderManagerTest.php b/Core/Tests/Authentication/AuthenticationProviderManagerTest.php index df25874..cc8b7c0 100644 --- a/Core/Tests/Authentication/AuthenticationProviderManagerTest.php +++ b/Core/Tests/Authentication/AuthenticationProviderManagerTest.php @@ -27,6 +27,16 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase new AuthenticationProviderManager(array()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testAuthenticateWithProvidersWithIncorrectInterface() + { + new AuthenticationProviderManager(array( + new \stdClass(), + )); + } + public function testAuthenticateWhenNoProviderSupportsToken() { $manager = new AuthenticationProviderManager(array( diff --git a/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php index ecad3e5..ebd845d 100644 --- a/Core/Tests/Encoder/BCryptPasswordEncoderTest.php +++ b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php @@ -47,8 +47,6 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase public function testResultLength() { - $this->skipIfPhpVersionIsNotSupported(); - $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertEquals(60, strlen($result)); @@ -56,21 +54,12 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase public function testValidation() { - $this->skipIfPhpVersionIsNotSupported(); - $encoder = new BCryptPasswordEncoder(self::VALID_COST); $result = $encoder->encodePassword(self::PASSWORD, null); $this->assertTrue($encoder->isPasswordValid($result, self::PASSWORD, null)); $this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null)); } - private function skipIfPhpVersionIsNotSupported() - { - if (PHP_VERSION_ID < 50307) { - $this->markTestSkipped('Requires PHP >= 5.3.7'); - } - } - /** * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException */ diff --git a/Core/Tests/SecurityContextTest.php b/Core/Tests/LegacySecurityContextTest.php index bcf9ad9..f1f7861 100644 --- a/Core/Tests/SecurityContextTest.php +++ b/Core/Tests/LegacySecurityContextTest.php @@ -15,7 +15,10 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; use Symfony\Component\Security\Core\SecurityContext; -class SecurityContextTest extends \PHPUnit_Framework_TestCase +/** + * @group legacy + */ +class LegacySecurityContextTest extends \PHPUnit_Framework_TestCase { private $tokenStorage; private $authorizationChecker; @@ -23,6 +26,8 @@ class SecurityContextTest extends \PHPUnit_Framework_TestCase protected function setUp() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $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); diff --git a/Core/Tests/User/UserTest.php b/Core/Tests/User/UserTest.php index 2fe6daa..f514eda 100644 --- a/Core/Tests/User/UserTest.php +++ b/Core/Tests/User/UserTest.php @@ -123,4 +123,13 @@ class UserTest extends \PHPUnit_Framework_TestCase $user->eraseCredentials(); $this->assertEquals('superpass', $user->getPassword()); } + + /** + * @covers Symfony\Component\Security\Core\User\User::__toString + */ + public function testToString() + { + $user = new User('fabien', 'superpass'); + $this->assertEquals('fabien', (string) $user); + } } diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php deleted file mode 100644 index cfbfdc1..0000000 --- a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php +++ /dev/null @@ -1,27 +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 LegacyUserPasswordValidator2Dot4ApiTest extends UserPasswordValidatorTest -{ - protected function getApiVersion() - { - return Validation::API_VERSION_2_4; - } -} diff --git a/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php b/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php index 7792913..047c929 100644 --- a/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php +++ b/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Security\Core\Tests\Validator\Constraints; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator; use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; @@ -28,9 +28,9 @@ abstract class UserPasswordValidatorTest extends AbstractConstraintValidatorTest const SALT = '^S4lt$'; /** - * @var SecurityContextInterface + * @var TokenStorageInterface */ - protected $securityContext; + protected $tokenStorage; /** * @var PasswordEncoderInterface @@ -44,13 +44,13 @@ abstract class UserPasswordValidatorTest extends AbstractConstraintValidatorTest protected function createValidator() { - return new UserPasswordValidator($this->securityContext, $this->encoderFactory); + return new UserPasswordValidator($this->tokenStorage, $this->encoderFactory); } protected function setUp() { $user = $this->createUser(); - $this->securityContext = $this->createSecurityContext($user); + $this->tokenStorage = $this->createTokenStorage($user); $this->encoder = $this->createPasswordEncoder(); $this->encoderFactory = $this->createEncoderFactory($this->encoder); @@ -97,7 +97,7 @@ abstract class UserPasswordValidatorTest extends AbstractConstraintValidatorTest { $user = $this->getMock('Foo\Bar\User'); - $this->securityContext = $this->createSecurityContext($user); + $this->tokenStorage = $this->createTokenStorage($user); $this->validator = $this->createValidator(); $this->validator->initialize($this->context); @@ -141,11 +141,11 @@ abstract class UserPasswordValidatorTest extends AbstractConstraintValidatorTest return $mock; } - protected function createSecurityContext($user = null) + protected function createTokenStorage($user = null) { $token = $this->createAuthenticationToken($user); - $mock = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); + $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'); $mock ->expects($this->any()) ->method('getToken') diff --git a/Core/User/User.php b/Core/User/User.php index ea2c6a4..d458b72 100644 --- a/Core/User/User.php +++ b/Core/User/User.php @@ -43,6 +43,11 @@ final class User implements AdvancedUserInterface $this->roles = $roles; } + public function __toString() + { + return $this->getUsername(); + } + /** * {@inheritdoc} */ diff --git a/Core/Util/SecureRandom.php b/Core/Util/SecureRandom.php index c0924df..f4167e4 100644 --- a/Core/Util/SecureRandom.php +++ b/Core/Util/SecureRandom.php @@ -43,9 +43,7 @@ final class SecureRandom implements SecureRandomInterface $this->logger = $logger; // determine whether to use OpenSSL - if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50304) { - $this->useOpenSsl = false; - } elseif (!function_exists('openssl_random_pseudo_bytes')) { + if (!function_exists('openssl_random_pseudo_bytes')) { if (null !== $this->logger) { $this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.'); } diff --git a/Core/Validator/Constraints/UserPasswordValidator.php b/Core/Validator/Constraints/UserPasswordValidator.php index 5f9ad2a..2dc7fee 100644 --- a/Core/Validator/Constraints/UserPasswordValidator.php +++ b/Core/Validator/Constraints/UserPasswordValidator.php @@ -12,8 +12,8 @@ namespace Symfony\Component\Security\Core\Validator\Constraints; use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\ConstraintDefinitionException; @@ -21,12 +21,12 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; class UserPasswordValidator extends ConstraintValidator { - private $securityContext; + private $tokenStorage; private $encoderFactory; - public function __construct(SecurityContextInterface $securityContext, EncoderFactoryInterface $encoderFactory) + public function __construct(TokenStorageInterface $tokenStorage, EncoderFactoryInterface $encoderFactory) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; $this->encoderFactory = $encoderFactory; } @@ -39,7 +39,7 @@ class UserPasswordValidator extends ConstraintValidator throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword'); } - $user = $this->securityContext->getToken()->getUser(); + $user = $this->tokenStorage->getToken()->getUser(); if (!$user instanceof UserInterface) { throw new ConstraintDefinitionException('The User object must implement the UserInterface interface.'); diff --git a/Core/composer.json b/Core/composer.json index 7bc1bf0..38054df 100644 --- a/Core/composer.json +++ b/Core/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "require-dev": { "symfony/phpunit-bridge": "~2.7", @@ -36,13 +36,12 @@ "ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5" }, "autoload": { - "psr-0": { "Symfony\\Component\\Security\\Core\\": "" } + "psr-4": { "Symfony\\Component\\Security\\Core\\": "" } }, - "target-dir": "Symfony/Component/Security/Core", "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } } } diff --git a/Core/phpunit.xml.dist b/Core/phpunit.xml.dist index 6b2ccb0..8a1a291 100644 --- a/Core/phpunit.xml.dist +++ b/Core/phpunit.xml.dist @@ -14,6 +14,7 @@ <php> <ini name="error_reporting" value="-1" /> </php> + <testsuites> <testsuite name="Symfony Security Component Core Test Suite"> <directory>./Tests/</directory> |