symfony2 登录记住我 [英] symfony2 login remember me
问题描述
我正在尝试在 Symfony2 记住我登录中实现功能.
I am trying to implement functionality in Symfony2 Remember Me login.
我有这个配置文件 security.yml
security:
firewalls:
frontend:
pattern: ^/
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
default_target_path: /index
success_handler: authentication_handler
logout:
path: /logout
target: /login
success_handler: authentication_handler
security: true
remember_me:
key: "%secret%"
lifetime: 120
path: /
access_denied_handler: accessdenied_handler
#primero deben de ir los usuarios anonimos si no se entra en loop redirect
access_control:
- { path: /login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/js, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_A }
- { path: ^/nuevoinforme, roles: ROLE_M }
- { path: ^/, roles: IS_AUTHENTICATED_REMEMBERED }
providers:
user_db:
entity: { class: mio\mioBundle\Entity\Empleado, property: username }
role_hierarchy:
ROLE_M: ROLE_U
ROLE_A: ROLE_U
encoders:
mio\mioBundle\Entity\Empleado: { algorithm: sha1 }
Symfony\Component\Security\Core\User\User: plaintext
当我登录时,cookie 正确存储在客户端上.但是,120 秒后,在尝试访问另一个 URL 时,它仍然认为客户端已登录,而我希望它被注销,因此我希望客户端被重定向到 /login
.
When I login, the cookie is properly stored on the client. However, after 120 seconds, while trying to access another URL, it still considers the client as logged-in while I expect it to be logged out and therefore I expect the client to be redirected to /login
.
我该如何解决这个问题?
How can I fix this issue?
推荐答案
您将 remember_me 生命周期
设置为 120
因此 cookie 会在 2 分钟内过期.
You set the remember_me lifetime
to 120
therefore the cookie expires within 2 minutes.
您应该将生命周期值设置为大于一天.
You should set the lifetime value greater than a day.
security:
firewalls:
frontend:
remember_me:
lifetime: 120 # this value should be greater than 120 seconds
我去掉了其余的参数,所以你可以看到我在说什么.
I stripped out the rest of the parameters so you can see what I am talking about.
这篇关于symfony2 登录记住我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!