Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
[2.1] Validator UserPassword fails after yesterdays update #5460
Comments
stof
referenced this issue
Sep 7, 2012
Closed
[2.1] Validtor UserPassword fails after yesterdays update #5461
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
MichaelHindley
Sep 10, 2012
After some more troubleshooting I'm able to pinpoint and reproduce the error.
Using a fresh Symfony 2.1 installation with composer, the autoloader seems to fail when it comes to the UserPassword validator.
The error:
Class 'Symfony\Component\Validator\Constraints\UserPassword' not found in D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\Mapping\Loader\AbstractLoader.php on line 63
It's trying to find the validator in the Validator component, but for some reason the UserPassword validator resides in the Security component(??).
UserPassword location:
Symfony/vendor/symfony/symfony/src/Symfony/Component/Validator/Constraints/UserPassword.php
Symfony looks for it in:
Symfony/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Validator/Constraint/UserPassword.php
Using:
src/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Form\Model\ChangePassword:
properties:
oldPassword:
- UserPassword:
message: "Wrong value for your current password"
from http://symfony.com/doc/master/reference/constraints/UserPassword.html
as an example.
Quick fix:
Move the files to the Validator and correct namespace.
Proper fix needed though.
MichaelHindley
commented
Sep 10, 2012
After some more troubleshooting I'm able to pinpoint and reproduce the error. Using a fresh Symfony 2.1 installation with composer, the autoloader seems to fail when it comes to the UserPassword validator. The error: It's trying to find the validator in the Validator component, but for some reason the UserPassword validator resides in the Security component(??). UserPassword location: Symfony looks for it in: Using: src/UserBundle/Resources/config/validation.ymlAcme\UserBundle\Form\Model\ChangePassword: Quick fix: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
MichaelHindley
Sep 10, 2012
Quick fix:
Move the files to the Validator and correct namespace.
Sorry, that doesn't seem to actually work. The UserPassword validator fails with constraintmessage even if a correct password is submitted if you try to move it.
MichaelHindley
commented
Sep 10, 2012
Quick fix: Sorry, that doesn't seem to actually work. The UserPassword validator fails with constraintmessage even if a correct password is submitted if you try to move it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
sstok
Sep 10, 2012
Contributor
Seems related to this one symfony/symfony-docs#1460
or not...
Are you using the latest version of the FOSUserBundle?
Seems related to this one symfony/symfony-docs#1460 Are you using the latest version of the FOSUserBundle? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
MichaelHindley
Sep 10, 2012
Yes, FOSUserBundle is on the latest update.
On a sidenote, if you include the UserPassword validator in your formtype and use it as a constraint,
then all other constraints in that formtype fail.
Example:
use Symfony\Component\Security\Core\Validator\Constraint\UserPassword;
use Symfony\Component\Validator\Constraints\Email;
'constraints' => new UserPassword(), # will work since you are pointing to it directly
'constraints' => new Email() # will not work at all on $form->isValid() calls, as if it doesnt even exist UPDATE: However if specified validation.yml as Email: ~ it does work.
This is starting to make less and less sense, is it possible i have a corrupt composer or something ?
MichaelHindley
commented
Sep 10, 2012
Yes, FOSUserBundle is on the latest update. On a sidenote, if you include the UserPassword validator in your formtype and use it as a constraint, Example: use Symfony\Component\Security\Core\Validator\Constraint\UserPassword; 'constraints' => new UserPassword(), # will work since you are pointing to it directly This is starting to make less and less sense, is it possible i have a corrupt composer or something ? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
sstok
Sep 10, 2012
Contributor
Ah there seems to be something wrong in the docs.
http://symfony.com/doc/2.1/reference/constraints/UserPassword.html
Bridge/Security does not exist, this should be Component/Security?
But the FOSUserBundle Form type is referring to the correct class, so thats not a problem.
Change UserPassword.
Acme\UserBundle\Form\Model\ChangePassword:
properties:
oldPassword:
- Symfony\Component\Security\Core\Validator\Constraint\UserPassword:
message: "Wrong value for your current password"
Ah there seems to be something wrong in the docs. Bridge/Security does not exist, this should be Component/Security? But the FOSUserBundle Form type is referring to the correct class, so thats not a problem. Change UserPassword.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
sstok
Sep 10, 2012
Contributor
UserPassword Constraint is not registered as alias (as far as I can see in the Security bundle).
So only using the full class name will work (see previous comment) or registering it yourself.
http://symfony.com/doc/current/cookbook/validation/custom_constraint.html#constraint-validators-with-dependencies
UserPassword Constraint is not registered as alias (as far as I can see in the Security bundle). So only using the full class name will work (see previous comment) or registering it yourself. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
@nihilnovi is this fixed for you? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
Closing this old issue without any feedback. |
MichaelHindley commentedSep 7, 2012
The validator (http://symfony.com/doc/master/reference/constraints/UserPassword.html) fails after updating to 2.1.
add('current_password', 'password', array( 'label' => 'form.current_password', 'translation_domain' => 'FOSUserBundle', 'mapped' => false, 'constraints' => new UserPassword(), <<<<< fails )); $builder->add('new', 'repeated', array( 'type' => 'password', 'options' => array('translation_domain' => 'FOSUserBundle'), 'first_options' => array('label' => 'form.new_password'), 'second_options' => array('label' => 'form.new_password_confirmation'), )); } ``` public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Cmf\UserBundle\Entity\User', 'intention' => 'change_password', )); } public function getName() { return 'fos_user_change_password'; } ``` } error given: [{"message":"The User must extend UserInterface","class":"Symfony\Component\Validator\Exception\ConstraintDefinitionException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Validator\Constraint\UserPasswordValidator.php","line":37,"args":[]},{"namespace":"Symfony\Component\Security\Core\Validator\Constraint","short_class":"UserPasswordValidator","class":"Symfony\Component\Security\Core\Validator\Constraint\UserPasswordValidator","type":"->","function":"validate","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":182,"args":[["string","password"],["object","Symfony\Component\Security\Core\Validator\Constraint\UserPassword"]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkConstraint","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Validator\Constraints\FormValidator.php","line":75,"args":[["object","Symfony\Component\Security\Core\Validator\Constraint\UserPassword"],["string","password"],["string","Default"],["string","children[current_password].data"]]},{"namespace":"Symfony\Component\Form\Extension\Validator\Constraints","short_class":"FormValidator","class":"Symfony\Component\Form\Extension\Validator\Constraints\FormValidator","type":"->","function":"validate","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":182,"args":[["object","Symfony\Component\Form\Form"],["object","Symfony\Component\Form\Extension\Validator\Constraints\Form"]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkConstraint","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":105,"args":[["object","Symfony\Component\Form\Extension\Validator\Constraints\Form"],["object","Symfony\Component\Form\Form"],["string","Default"],["string","children[current_password]"],["string","Symfony\Component\Form\Form"]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkObjectForGroup","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":85,"args":[["object","Symfony\Component\Validator\Mapping\ClassMetadata"],["object","Symfony\Component\Form\Form"],["string","Default"],["string","children[current_password]"]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkObject","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":163,"args":[["object","Symfony\Component\Validator\Mapping\ClassMetadata"],["object","Symfony\Component\Form\Form"],["string","Default"],["string","children[current_password]"]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkReference","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":156,"args":[["object","Symfony\Component\Form\Form"],["string","Default"],["string","children[current_password]"],["boolean",false],["boolean",false]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkReference","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":140,"args":[["array",{"current_password":["object","Symfony\Component\Form\Form"],"new":["object","Symfony\Component\Form\Form"]}],["string","Default"],["string","children"],["boolean",true],["boolean",false]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkMember","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":119,"args":[["object","Symfony\Component\Validator\Mapping\PropertyMetadata"],["array",{"current_password":["object","Symfony\Component\Form\Form"],"new":["object","Symfony\Component\Form\Form"]}],["string","Default"],["string","children"],["null",null]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkProperty","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":111,"args":[["object","Symfony\Component\Validator\Mapping\ClassMetadata"],["string","children"],["object","Symfony\Component\Form\Form"],["string","Default"],["string","children"],["null",null]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkObjectForGroup","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\GraphWalker.php","line":85,"args":[["object","Symfony\Component\Validator\Mapping\ClassMetadata"],["object","Symfony\Component\Form\Form"],["string","Default"],["string",""]]},{"namespace":"Symfony\Component\Validator","short_class":"GraphWalker","class":"Symfony\Component\Validator\GraphWalker","type":"->","function":"walkObject","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\Validator.php","line":64,"args":[["object","Symfony\Component\Validator\Mapping\ClassMetadata"],["object","Symfony\Component\Form\Form"],["string","Default"],["string",""]]},{"namespace":"Symfony\Component\Validator","short_class":"Validator","class":"Symfony\Component\Validator\Validator","type":"->","function":"Symfony\Component\Validator\{closure}","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\Validator.php","line":138,"args":[["object","Symfony\Component\Validator\GraphWalker"],["string","Default"]]},{"namespace":"Symfony\Component\Validator","short_class":"Validator","class":"Symfony\Component\Validator\Validator","type":"->","function":"validateGraph","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Validator\Validator.php","line":67,"args":[["object","Symfony\Component\Form\Form"],["object","Closure"],["null",null]]},{"namespace":"Symfony\Component\Validator","short_class":"Validator","class":"Symfony\Component\Validator\Validator","type":"->","function":"validate","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener.php","line":55,"args":[["object","Symfony\Component\Form\Form"]]},{"namespace":"Symfony\Component\Form\Extension\Validator\EventListener","short_class":"ValidationListener","class":"Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener","type":"->","function":"validateForm","file":null,"line":null,"args":[["object","Symfony\Component\Form\FormEvent"]]},{"namespace":"","short_class":"","class":"","type":"","function":"call_user_func","file":"D:\Dev\wamp\www\cmf\app\cache\dev\classes.php","line":4781,"args":[["array",[["object","Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener"],["string","validateForm"]]],["object","Symfony\Component\Form\FormEvent"]]},{"namespace":"Symfony\Component\EventDispatcher","short_class":"EventDispatcher","class":"Symfony\Component\EventDispatcher\EventDispatcher","type":"->","function":"doDispatch","file":"D:\Dev\wamp\www\cmf\app\cache\dev\classes.php","line":4695,"args":[["array",[["array",[["object","Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener"],["string","validateForm"]]]]],["string","form.post_bind"],["object","Symfony\Component\Form\FormEvent"]]},{"namespace":"Symfony\Component\EventDispatcher","short_class":"EventDispatcher","class":"Symfony\Component\EventDispatcher\EventDispatcher","type":"->","function":"dispatch","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\ImmutableEventDispatcher.php","line":42,"args":[["string","form.post_bind"],["object","Symfony\Component\Form\FormEvent"]]},{"namespace":"Symfony\Component\EventDispatcher","short_class":"ImmutableEventDispatcher","class":"Symfony\Component\EventDispatcher\ImmutableEventDispatcher","type":"->","function":"dispatch","file":"D:\Dev\wamp\www\cmf\vendor\symfony\symfony\src\Symfony\Component\Form\Form.php","line":603,"args":[["string","form.post_bind"],["object","Symfony\Component\Form\FormEvent"]]},{"namespace":"Symfony\Component\Form","short_class":"Form","class":"Symfony\Component\Form\Form","type":"->","function":"bind","file":"D:\Dev\wamp\www\cmf\src\Cmf\UserBundle\Controller\UsersController.php","line":24,"args":[["array",{"current_password":["string","password"],"new":["array",{"first":["string","test1"],"second":["string","test1"]}]}]]},{"namespace":"Cmf\UserBundle\Controller","short_class":"UsersController","class":"Cmf\UserBundle\Controller\UsersController","type":"->","function":"processForm","file":"D:\Dev\wamp\www\cmf\src\Cmf\UserBundle\Controller\UsersController.php","line":138,"args":[["object","Cmf\UserBundle\Entity\User"],["object","Cmf\UserBundle\Form\ChangePasswordType"]]},{"namespace":"Cmf\UserBundle\Controller","short_class":"UsersController","class":"Cmf\UserBundle\Controller\UsersController","type":"->","function":"patchPasswordUserAction","file":null,"line":null,"args":[["string","2"]]},{"namespace":"","short_class":"","class":"","type":"","function":"call_user_func_array","file":"D:\Dev\wamp\www\cmf\app\bootstrap.php.cache","line":1419,"args":[["array",[["object","Cmf\UserBundle\Controller\UsersController"],["string","patchPasswordUserAction"]]],["array",[["string","2"]]]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"HttpKernel","class":"Symfony\Component\HttpKernel\HttpKernel","type":"->","function":"handleRaw","file":"D:\Dev\wamp\www\cmf\app\bootstrap.php.cache","line":1383,"args":[["object","Symfony\Component\HttpFoundation\Request"],["string","1"]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"HttpKernel","class":"Symfony\Component\HttpKernel\HttpKernel","type":"->","function":"handle","file":"D:\Dev\wamp\www\cmf\app\bootstrap.php.cache","line":1559,"args":[["object","Symfony\Component\HttpFoundation\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\Bundle\FrameworkBundle","short_class":"HttpKernel","class":"Symfony\Bundle\FrameworkBundle\HttpKernel","type":"->","function":"handle","file":"D:\Dev\wamp\www\cmf\app\bootstrap.php.cache","line":610,"args":[["object","Symfony\Component\HttpFoundation\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"Kernel","class":"Symfony\Component\HttpKernel\Kernel","type":"->","function":"handle","file":"D:\Dev\wamp\www\cmf\web\app_dev.php","line":28,"args":[["object","Symfony\Component\HttpFoundation\Request"]]}]}] Removing the 'constraints' => new UserPassword(), solves the issue, but then the validation is gone. This is after doing composer update @ 2.1 release yesterday and a default config FOSUserBundle and FOSRestBundle.