微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何分别为每个人定义“记住我”? Symfony 5

如何解决如何分别为每个人定义“记住我”? Symfony 5

我在 Symfony 5(安全部分)中创建了两个身份验证“admin”和“user”

我将它们设置在 main 防火墙中。

现在我如何为每个单独定义“记住我”??

对于管理员

remember_me:
    secret: '%kernel.secret%'
    lifetime: 86400

对于用户

remember_me:
    secret: '%kernel.secret%'
    lifetime: 32598000

我的 security.yaml 是:

security:
    encoders:
        App\Entity\Admin:
            algorithm: auto
        App\Entity\User:
            algorithm: auto
    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_admin_provider:
            entity:
                class: App\Entity\Admin
                property: username
        app_user_provider:
            entity:
                class: App\Entity\User
                property: username
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: true
            lazy: true
            provider: app_user_provider
            guard:
                authenticators:
                    - App\Security\AdminAuthenticator
                    - App\Security\UserAuthenticator
                entry_point: App\Security\UserAuthenticator
            logout:
                path: app_logout
                # where to redirect after logout
                # target: app_any_route
            # activate different ways to authenticate
            # https://symfony.com/doc/current/security.html#firewalls-authentication
            # https://symfony.com/doc/current/security/impersonating_user.html
            # switch_user: 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: ^/admin,roles: ROLE_ADMIN }
        # - { path: ^/profile,roles: ROLE_USER }

解决方法

您可以将主防火墙一分为二,并根据需要为每个角色设置 remember_me 参数。您可以从此处阅读有关防火墙的更多信息:https://symfony.com/doc/current/security.html#firewalls-authentication

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。