Symfony 4重定向循环以从多个角色登录



我正在设置Symfony 4来创建新网站,但是当我想与具有多个角色ROLE_USERROLE_ADMIN的用户登录时,我被重定向到登录页面。只需一个角色ROLE_USER我就可以登录,如何解决这个问题?

配置是PHP 7.2,Symfony 4.2,Web服务器内置Symfony"server:start"。我尝试更改安全配置,但没有任何变化。

security.yaml

security:
    encoders:
        AppEntityUser: plaintext
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        secured_area:
            # this firewall applies to all URLs
            pattern: ^/
            # but the firewall does not require login on every page
            # denying access is done in access_control or in your controllers
            anonymous: ~
            # This allows the user to login by submitting a username and password
            # Reference: http://symfony.com/doc/current/cookbook/security/form_login_setup.html
            form_login:
                # fos user bundle handles the form login
                #provider: fos_userbundle
                # The route name that the login form submits to
                check_path: fos_user_security_check
                # The name of the route where the login form lives
                # When the user tries to access a protected page, they are redirected here
                login_path: fos_user_security_login
                # Secure the login form against CSRF
                # Reference: http://symfony.com/doc/current/cookbook/security/csrf_in_login_form.html
                csrf_token_generator: security.csrf.token_manager
            logout:
                # The route name the user can go to in order to logout
                path: fos_user_security_logout
                # The name of the route to redirect to after logging out
                target: homepage
    # 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: ^/categories, role: ROLE_ADMIN }
        - { path: ^/tags, role: ROLE_ADMIN }
        - { path: ^/typewords, role: ROLE_ADMIN }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, role: ROLE_ADMIN }
        - { path: ^/, role: ROLE_USER }

routes.yaml

controllers:
    resource: '../src/Controller/'
    type: annotation
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
easy_admin_bundle:
    resource: '@EasyAdminBundle/Controller/EasyAdminController.php'
    prefix: /admin
    type: annotation

我希望使用ROLE_USER以外的其他ROLE登录。

按层次结构,具有ROLE_ADMIN的用户自动拥有ROLE_USER 。因此,只需从该用户中删除ROLE_USER即可。不确定如何从用户提供程序加载角色,请同时检查如何在数据库中编写ROLE_ADMIN或用于映射 User 实体的内容。(包括用户实体的映射文件,以便进一步了解(

相关内容

  • 没有找到相关文章

最新更新