Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to implement functionality in Symfony2 Remember Me login.

I have this configuration file 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: miomioBundleEntityEmpleado, property: username }
    role_hierarchy:
        ROLE_M: ROLE_U
        ROLE_A: ROLE_U

    encoders:
        miomioBundleEntityEmpleado: { algorithm: sha1 }
        SymfonyComponentSecurityCoreUserUser: plaintext

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
329 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...