Search code examples
cookiesspring-securityspring-java-configremember-me

Remember me cookie is not showing after browser is closed and reopened?


I have trying to add a remember me function in my web application. This is the configurations I made with Spring.

..........
    .rememberMe().rememberMeParameter("remember-me").tokenRepository(tokenRepository)
                .tokenValiditySeconds(86400).and().csrf().and().exceptionHandling().accessDeniedPage("/access_denied");
............

@Bean
public PersistentTokenBasedRememberMeServices getPersistentTokenBasedRememberMeServices() {
    PersistentTokenBasedRememberMeServices tokenBasedservice = new PersistentTokenBasedRememberMeServices(
            "remember-me", userDetailsService, tokenRepository);
    return tokenBasedservice;
}

Once I logged into the application and checked for the cookies I see remember-me cookie as below which is to be expired tomorrow.

enter image description here

But once I closed the browser and opened again I'm logged out of the application and when checking for the cookie , remember-me cookie is not shown as well.

So I want to know

  1. Is this the normal behavior of remember me functionality?
  2. Am I able to keep logged until the remember-me cookie expires?
  3. Why do the remember-me cookie disappears when the browser is reopened?

edit: This is the browser settings for cookies

enter image description here

Firefox configuration:

enter image description here


Solution

  • You have to turn off Keep local data only until you quit your browser to keep your cookies, see Google Chrome Help:

    Delete cookies after you close Chrome

    You can let sites remember information during your browsing session, but automatically delete the cookies when you quit Chrome.

    1. On your computer, open Google Chrome.
    2. At the top right, click More More and then Settings.
    3. At the bottom, click Advanced.
    4. Under "Privacy and security," click Content settings.
    5. Click Cookies.
    6. Turn on Keep local data only until you quit your browser.