3
votes

I'm using Symfony 3.3 with FOSUserBundle 2.0. I can't get the reset password feature to work. I go to request resetting page, type an email or username and click on submit and it redirects me to login page without any error shown in the view. I looked at the log and it gives me this error :

security.DEBUG: Access denied, the user is not fully authenticated; redirecting to authentication entry point. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException(code: 403): Access Denied. at .../vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php:125)"} []

Security.yml :

security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512

{...}

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
            default_target_path: /verifInit
        logout:       true
        anonymous:    true
        switch_user:
            role: ROLE_ADMIN
            provider: fos_userbundle
            parameter: username
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

providers:
    in_memory:
        memory:
            users:
                user:  { password: userpass, roles: [ 'ROLE_USER' ] }
                admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
    fos_userbundle:
        id: fos_user.user_provider.username

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

When I remove switch_user part in security.yml, it's working well. Do you have an idea why ? I need switch_user feature for my project so I can't remove it.

1
can you post the contents of security.yml ? and/or if you have added any Auth related code in the controller responsible for this action ? - Vamsi Krishna B
I edited my question - Kristen Joseph-Delaffon
you did not change the user Entity ? - Malek Zarkouna
tried clearing browser cookies and server side sessions ( cache:clear ) ? - Vamsi Krishna B
When I remove switch_user part from security.yml, it's working. Any idea why eset password doesn't work along with switch_user ? I used Symfony documentation to setup switch_user. - Kristen Joseph-Delaffon

1 Answers

0
votes
switch_user: true

and

security:
    role_hierarchy:
        ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]

Try this way.