-2

I have set up a role like : { path: ^/, role: ROLE_USER } and it redirects, if not authenticated to /login. How can I change this redirect url?

Below my security.yaml:

security:
  encoders:
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

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

    main_login:
        pattern:   ^/(fr|en|zh)/login$
        anonymous: true

    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_token_generator: security.csrf.token_manager
            check_path: fos_user_security_check
            default_target_path: iot6_HomeBundle
        logout:
            path:   fos_user_security_logout
            target: fos_user_security_login



        anonymous:    true



# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
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 }
    - { path: ^/, role: ROLE_USER }
    #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
Stefano Maglione
  • 3,946
  • 11
  • 49
  • 96
  • Check this answer: https://stackoverflow.com/a/19608870/1159013 – Bloops Mar 12 '19 at 15:20
  • 2
    Possible duplicate of [How to customize FOS UserBundle URLs](https://stackoverflow.com/questions/19608458/how-to-customize-fos-userbundle-urls) – Nico Haase Mar 12 '19 at 15:26

1 Answers1

1

If I understand your question correctly, you need to override FOSUserBundle's route. Like that:

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

# ...

fos_user_security_login:
  path:      /yourRoute/login
  defaults:  { _controller: FOSUserBundle:Security:login, _method: POST }
Evgeny Ruban
  • 1,357
  • 1
  • 14
  • 20