Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 security when using i18n routing?

Tags:

symfony

I'm using JMSI18nRoutingBundle for routing translations, with custom configuration, that is no prefix for all routes:

# app/config/config.yml
jms_i18n_routing:
  default_locale: it
  locales: [it, en]
  strategy: custom

www.example.com/contatti
www.example.com/contact

This is working fine, a like that bundle. Not i have to develop the admin part of the project, of course securing it. I'm stuck at security configuration (an excerpt):

# app/config/config.yml
security:
    firewalls:
        secured_area:
            pattern:    ^/
            anonymous: ~
            form_login:
                login_path:  /login
                check_path:  /login_check

login_path is statically defined using security.yml. So, how i'm supposed to specify the correct login (localized) path? Assuming form is accessibile using:

www.example.com/accesso
www.example.com/login
like image 389
gremo Avatar asked Mar 08 '12 16:03

gremo


1 Answers

As Wojciech Jasiński mentioned already in the comments, you should use route name instead of pattern.

Just to bring some light...
You should define your route

gremo_login_path:
    pattern: /login

...and use it in security.yml

security:
    firewalls:
        secured_area:
            pattern:    ^/
            anonymous: ~
            form_login:
                login_path:  gremo_login_path
                check_path:  /login_check

See also related issues:
https://github.com/schmittjoh/JMSI18nRoutingBundle/issues/7
https://github.com/symfony/symfony/pull/3791/files

like image 76
Vitalii Zurian Avatar answered Sep 27 '22 02:09

Vitalii Zurian