Internationalized routing don’t work fine with security access controls

I’m trying to use Internationalized routing.

So for one route many url.
But one route still being uniquely identifiy by her name.

This is a greate feature but the doc don’t says how to deal with the security component.
In fact, i’m using url to make a basic secure of the app.

But since every url can be different regarding on the locale, the only way I found to make thing still working is to dupplicate as many path as route name got.

Well… I show with some examples.

So that’s my security.yaml right now :

# ./config/packages/security.yaml @ line 27 -- 41
        # Allow every user to visit index_no_locale page (Default page when no locale is selected).
        # This will redirect to login page with default locale.
        - { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY}
        # Allow anonymous to visit login page.
        - { path: ^(/en/login|/fr/connexion|/de/verbindung), roles: IS_AUTHENTICATED_ANONYMOUSLY}
        # Allow anonymous to visit password_reset page.
        - { path: ^(/en/password/reset|/fr/mot-de-passe/reinitialisation|/de/passwort/zur├╝cksetzen), roles: IS_AUTHENTICATED_ANONYMOUSLY}
        # Allow anonymous to visit email_send_password_forgot
        - { path: ^(/en/email/send/password/forgot|/fr/courriel/envoyer/mot-de-passe|/de/email/schreiben/passwort/vergessen), roles: IS_AUTHENTICATED_ANONYMOUSLY}
        # Allow only admin to visit admin url
        - { path: ^/admin, roles: IS_ADMIN}
        # Allow authenticated user ONLY to visit every other urls
        # Specific user right controls are managed inside controller
        - { path: ^/, roles: IS_AUTHENTICATED_FULLY}

As I say this is working, but I’ve got to dupplicate path for every existing route.

I let you see the route for better understand :

> php bin/console debug:router
  Name                             Method   Scheme   Host   Path      
-------------------------------- -------- -------- ------ --------------------
  password_reset.en                ANY      ANY      ANY    /{_locale}/password/reset/{user_id}/{token_value}                    ANY      ANY      ANY    /{_locale}/mot-de-passe/reinitialisation/{user_id}/{token_value}                ANY      ANY      ANY    /{_locale}/passwort/zur├╝cksetzen/{user_id}/{token_value}    
  login.en                         ANY      ANY      ANY    /{_locale}/login                                                              ANY      ANY      ANY    /{_locale}/connexion                                                          ANY      ANY      ANY    /{_locale}/verbindung                                       
  logout                           ANY      ANY      ANY    /{_locale}/logout                                           
  index_no_locale                  ANY      ANY      ANY    /                 

I really don’t like this for evident reason of redondent modifications to opeer each time a url have to be added or modifyed.

The main problem is when user is not logged in and visit a url where IS_AUTHENTICATED_FULLY role is required.

So now the ‘Voter’ say that access is denied and redirect response to login_path define into security.yaml

Here is the problem. I can’t define a proper path to login_path because I can’t guess what was the locale used by the user. So I hardcoded this :

# ./config/packages/security.yaml @ line 1 -- 21
            anonymous: true

                login_path: /en/login
                check_path: /en/login
                provider:   my_provider
                path: /en/logout

Same for logout actually…

Any help would be appreciate !

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *