5

How can I secure actions with locale - this was pretty easy in symfony1.4. I use now symfony2.3:

My security.yml:

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

    login:
        pattern:  frontend_account_login
        security: false


    secured_area:
        pattern:    ^/
        anonymous: ~
        http_basic:
            realm: "Secured Demo Area"
        form_login:
            check_path: frontend_account_security_check
            login_path: frontend_account_login
            use_referer:        true
            default_target_path: frontend_account_hello
        logout:
            path:   /logout
            target: frontend_account_login            #anonymous: ~
        #http_basic:
        #    realm: "Secured Demo Area"

access_control:
    #This works:
    - { path: ^/de/account/secured/, roles: ROLE_ADMIN }
    - { path: ^/en/account/secured/, roles: ROLE_ADMIN } 
    #I want it kind of that way
    - { path: ^/{_locale}/account/secured/, roles: ROLE_ADMIN }

I read a post with regex: ^/[a-z]+/account/secured/. But it doesn't work. Any idea how I can secure areas with locale. I found some posts here but they all don't work.

Thanks!!!

2 Answers2

3

If you have only two locales:

- { path: ^/(en|de)/account/secured/, roles: ROLE_ADMIN }
A.L
  • 10,259
  • 10
  • 67
  • 98
1

Answer of YoannCh is also correct.

Shouldn't you replace the {_locale} by a %_locale% or %locale%

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64