简体   繁体   English

Symfony 4 - 登录页面总是重定向到自己

[英]Symfony 4 - login page always redirects to itself

I was trying to restrict access to the / path for the ROLE_USER, but when it redirects once to the login page, it keeps doing it and I get this : ERR_TOO_MANY_REDIRECTS 我试图限制对ROLE_USER的/ path的访问,但当它重定向一次到登录页面时,它会继续这样做,我得到这个: ERR_TOO_MANY_REDIRECTS

Here's my security.yaml : 这是我的security.yaml:

security:
    encoders:
        App\Entity\User:
            algorithm: bcrypt


    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: true
            guard:
                authenticators:
                    - App\Security\UserAuthenticator
            form_login: true
    access_control:
         - { path: ^/admin, roles: ROLE_ADMIN }
         - { path: ^/, roles: ROLE_USER }
        # - { path: ^/profile, roles: ROLE_USER }

    role_hierarchy:
      ROLE_ADMIN:       ROLE_USER
      ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

Here's my SecurityController : 这是我的SecurityController:

    /**
     * @Route("/login", name="app_login")
     */
    public function login(AuthenticationUtils $authenticationUtils): Response
    {
        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();
        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
    }

我不得不将此添加到security.yml:

- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM