Julie
Julie

Reputation: 583

Having a firewall issues when using FOSUserBundle

I am trying to incorporate FOSUserBundle in existing project that has an authentication system for admin and I am using FOSUserBundle for users but I have a firwall error!

I am using this url: http://localhost/myproject/web/app_dev.php/fr/user/login

and the error :

InvalidConfigurationException in BaseNode.php line 313:
Invalid configuration for path "security.firewalls.Fos_secured_area": The check_path "/login_check" for login method "form_login" is not matched by the firewall pattern "^/(fr|en)/user/.*".

this is my security.yml

 admin:
            entity: { class: AppBundle:Admin}

        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:

        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false

        Fos_secured_area:
            pattern:  ^/(%app_locales%)/User/.*
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager
            logout:       true
            anonymous:    true



        admin_secured_area:
            pattern: ^/(%app_locales%)/admin/.*
            anonymous: true
            provider: admin
            form_login:
                check_path: security_admin_login 
                login_path: security_admin_login
                csrf_token_generator: security.csrf.token_manager
                default_target_path: admin_page
            logout:
                path: admin_logout
                target: homepage
  access_control:

     - { path: ^/(%app_locales%)/User/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/(%app_locales%)/User/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/(%app_locales%)/User/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

my routing.yml

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"


app:
    resource: '@AppBundle/Controller/'
    type:     annotation
    prefix:   /{_locale}
    requirements:
        _locale: '%app_locales%'
    defaults:
        _locale: '%locale%'

Upvotes: 1

Views: 71

Answers (1)

carmel
carmel

Reputation: 1012

try changing

pattern: ^/(%app_locales%)/User/.*

to

pattern: ^/

I think there is no need for that pattern in your case

Short explanation: The pattern is a regex that determens what firewall rule will apply for what route.

Fosuserbundle uses a route that looks like /login_check for the callback of the login action. And since it doesn't match your pattern the Fos_secured_area rull won't apply for that route.

Upvotes: 1

Related Questions