Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony firewall doesn't redirect me if i'm not login

Ok guys, it has been 10 hours that I search a solution for my problem. My firewall on Symfony 2.7 doesn't redirect me if i'm not logged in.

If I go on domain.com/admin/, the firewall should redirect me on /login, but not.

I use FOSUSerBundle. I alway obtain this error message :

You are not authenticated 401 Unauthorized - HttpException 1 linked Exception: AuthenticationCredentialsNotFoundException »

Here is my code:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    admin:
        pattern: ^/
        context: site
        form_login:
            provider: fos_userbundle
            check_path: /login_check
            login_path: /login
        logout:
            path: /admin/logout
        anonymous: false

My access control:

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 }

Here is the code in PhpStorm if you prefer : Image1

Thanks for your help!

like image 875
coolfarmer Avatar asked Aug 15 '15 20:08

coolfarmer


1 Answers

Finally I found the problem!! FOSRestBundle have a conflict with FOSUserBundle. If I disable RestBundle in config.yml, all works!!

So, I just move my API bundle in another symfony project. One project for my API and one project for my site.

like image 77
coolfarmer Avatar answered Nov 17 '22 20:11

coolfarmer