summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2013-02-04 13:42:02 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2013-02-04 13:42:02 +0100
commit49f2eb420b3835d1032dbad4c52e1caa70930cf5 (patch)
treef721807999722d6d0d3c3e2b5b9356433b05c498
parented807c3657bb1c8c82606f80cb2b24639b5c6df1 (diff)
parentfd9ade7daddcbda27d0bd69cd2a25da516389a49 (diff)
downloadsymfony-security-49f2eb420b3835d1032dbad4c52e1caa70930cf5.zip
symfony-security-49f2eb420b3835d1032dbad4c52e1caa70930cf5.tar.gz
symfony-security-49f2eb420b3835d1032dbad4c52e1caa70930cf5.tar.bz2
Merge branch '2.2'
* 2.2: fixed regression in the Finder component (it was possible to use it without using exec before, closes #6357) fixed a circular call (closes #6864) typo [Security] [Tests] added unit tests for the UserPasswordValidator class and made the validator service for the UserPassword constraint configurable. fixed wrong indentation tweaked previous commit [HttpKernel] Fix the URI signer (closes #6801) Add Arabic translations. [HttpKernel] fixed regression when rendering an inline controller and passing some objects (closes #6822) [FrameworkBundle] fixed typo renamed some classes and Twig functions to more descriptive names (refs #6871) Classcollectionloader: fix traits + enhancements Fix a deprecated method call in the tests Update `composer.json` files: - to allow versions ~2.2 (>=2.2,<3.0) of Doctrine DBAL, ORM & Common - fixed Propel1 versions difference between main and bridge files - fixed Twig versions difference between main and bridge files - to allow versions ~1.11 (>=1.11,<2.0) of Twig - fixed Locale ext-intl version to accept all, not non-existing version Correct comment in NativeSessionStorage regarding session.save_handler [Security] Add PHPDoc to AuthenticationEvents
-rw-r--r--Core/AuthenticationEvents.php19
-rw-r--r--Core/Validator/Constraint/UserPassword.php3
-rw-r--r--Resources/translations/security.ar.xlf71
-rw-r--r--Tests/Core/Validator/Constraint/UserPasswordValidatorTest.php161
-rw-r--r--composer.json4
5 files changed, 255 insertions, 3 deletions
diff --git a/Core/AuthenticationEvents.php b/Core/AuthenticationEvents.php
index 1e0e6ff..90b7142 100644
--- a/Core/AuthenticationEvents.php
+++ b/Core/AuthenticationEvents.php
@@ -13,7 +13,26 @@ namespace Symfony\Component\Security\Core;
final class AuthenticationEvents
{
+ /**
+ * The AUTHENTICATION_SUCCESS event occurs after a user is authenticated
+ * by one provider.
+ *
+ * The event listener method receives a
+ * Symfony\Component\Security\Core\Event\AuthenticationEvent instance.
+ *
+ * @var string
+ */
const AUTHENTICATION_SUCCESS = 'security.authentication.success';
+ /**
+ * The AUTHENTICATION_FAILURE event occurs after a user cannot be
+ * authenticated by any of the providers.
+ *
+ * The event listener method receives a
+ * Symfony\Component\Security\Core\Event\AuthenticationFailureEvent
+ * instance.
+ *
+ * @var string
+ */
const AUTHENTICATION_FAILURE = 'security.authentication.failure';
}
diff --git a/Core/Validator/Constraint/UserPassword.php b/Core/Validator/Constraint/UserPassword.php
index 3279e02..e90d9af 100644
--- a/Core/Validator/Constraint/UserPassword.php
+++ b/Core/Validator/Constraint/UserPassword.php
@@ -19,9 +19,10 @@ use Symfony\Component\Validator\Constraint;
class UserPassword extends Constraint
{
public $message = 'This value should be the user current password.';
+ public $service = 'security.validator.user_password';
public function validatedBy()
{
- return 'security.validator.user_password';
+ return $this->service;
}
}
diff --git a/Resources/translations/security.ar.xlf b/Resources/translations/security.ar.xlf
new file mode 100644
index 0000000..fd18ee6
--- /dev/null
+++ b/Resources/translations/security.ar.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>حدث خطأ اثناء الدخول.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>لم استطع العثور على معلومات الدخول.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>لم يكتمل طلب الدخول نتيجه عطل فى النظام.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>معلومات الدخول خاطئة.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>ملفات تعريف الارتباط(cookies) تم استخدامها من قبل شخص اخر.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>ليست لديك الصلاحيات الكافية لهذا الطلب.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>رمز الموقع غير صحيح.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>انتهت صلاحية(digest nonce).</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>لا يوجد معرف للدخول يدعم الرمز المستخدم للدخول.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>لا يوجد صلة بينك و بين الموقع اما انها انتهت او ان متصفحك لا يدعم خاصية ملفات تعريف الارتباط (cookies).</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>لم استطع العثور على الرمز.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>لم استطع العثور على اسم الدخول.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>انتهت صلاحية الحساب.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>انتهت صلاحية معلومات الدخول.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>الحساب موقوف.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>الحساب مغلق.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Tests/Core/Validator/Constraint/UserPasswordValidatorTest.php b/Tests/Core/Validator/Constraint/UserPasswordValidatorTest.php
new file mode 100644
index 0000000..e3bcbf4
--- /dev/null
+++ b/Tests/Core/Validator/Constraint/UserPasswordValidatorTest.php
@@ -0,0 +1,161 @@
+<?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\Validator\Constraint;
+
+use Symfony\Component\Security\Core\Validator\Constraint\UserPassword;
+use Symfony\Component\Security\Core\Validator\Constraint\UserPasswordValidator;
+
+class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
+{
+ const PASSWORD_VALID = true;
+ const PASSWORD_INVALID = false;
+
+ protected $context;
+
+ protected function setUp()
+ {
+ if (false === class_exists('Symfony\Component\Validator\Validator')) {
+ $this->markTestSkipped('The Validator component is required for this test.');
+ }
+
+ $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
+ }
+
+ protected function tearDown()
+ {
+ $this->context = null;
+ }
+
+ public function testPasswordIsValid()
+ {
+ $user = $this->createUser();
+ $securityContext = $this->createSecurityContext($user);
+
+ $encoder = $this->createPasswordEncoder(static::PASSWORD_VALID);
+ $encoderFactory = $this->createEncoderFactory($encoder);
+
+ $validator = new UserPasswordValidator($securityContext, $encoderFactory);
+ $validator->initialize($this->context);
+
+ $this
+ ->context
+ ->expects($this->never())
+ ->method('addViolation')
+ ;
+
+ $validator->validate('secret', new UserPassword());
+ }
+
+ public function testPasswordIsNotValid()
+ {
+ $user = $this->createUser();
+ $securityContext = $this->createSecurityContext($user);
+
+ $encoder = $this->createPasswordEncoder(static::PASSWORD_INVALID);
+ $encoderFactory = $this->createEncoderFactory($encoder);
+
+ $validator = new UserPasswordValidator($securityContext, $encoderFactory);
+ $validator->initialize($this->context);
+
+ $this
+ ->context
+ ->expects($this->once())
+ ->method('addViolation')
+ ;
+
+ $validator->validate('secret', new UserPassword());
+ }
+
+ public function testUserIsNotValid()
+ {
+ $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
+
+ $user = $this->getMock('Foo\Bar\User');
+ $encoderFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
+ $securityContext = $this->createSecurityContext($user);
+
+ $validator = new UserPasswordValidator($securityContext, $encoderFactory);
+ $validator->initialize($this->context);
+ $validator->validate('secret', new UserPassword());
+ }
+
+ protected function createUser()
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+
+ $mock
+ ->expects($this->once())
+ ->method('getPassword')
+ ->will($this->returnValue('s3Cr3t'))
+ ;
+
+ $mock
+ ->expects($this->once())
+ ->method('getSalt')
+ ->will($this->returnValue('^S4lt$'))
+ ;
+
+ return $mock;
+ }
+
+ protected function createPasswordEncoder($isPasswordValid = true)
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
+
+ $mock
+ ->expects($this->once())
+ ->method('isPasswordValid')
+ ->will($this->returnValue($isPasswordValid))
+ ;
+
+ return $mock;
+ }
+
+ protected function createEncoderFactory($encoder = null)
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
+
+ $mock
+ ->expects($this->once())
+ ->method('getEncoder')
+ ->will($this->returnValue($encoder))
+ ;
+
+ return $mock;
+ }
+
+ protected function createSecurityContext($user = null)
+ {
+ $token = $this->createAuthenticationToken($user);
+
+ $mock = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $mock
+ ->expects($this->once())
+ ->method('getToken')
+ ->will($this->returnValue($token))
+ ;
+
+ return $mock;
+ }
+
+ protected function createAuthenticationToken($user = null)
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $mock
+ ->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($user))
+ ;
+
+ return $mock;
+ }
+}
diff --git a/composer.json b/composer.json
index 468b720..1e3f001 100644
--- a/composer.json
+++ b/composer.json
@@ -25,8 +25,8 @@
"symfony/form": "2.2.*",
"symfony/routing": "2.2.*",
"symfony/validator": "2.2.*",
- "doctrine/common": ">=2.2,<2.4-dev",
- "doctrine/dbal": ">=2.2,<2.4-dev",
+ "doctrine/common": "~2.2",
+ "doctrine/dbal": "~2.2",
"psr/log": "~1.0"
},
"suggest": {