24 comments on “Spring Security Remember Me Example

  1. I have a user that just makes a API calls to spring secure application.
    I just want to make a one time authentication to that user to access my secure application
    and I don’t want to sign in again to make the subsequent calls.
    How can I achieve this?

  2. Where the loginProcessingUrl, i.e., login_check is defined in the code. How framework in handling ‘login_check’ URL?

  3. I’m trying to add Rememeber Me to my web application. Application based on Spring and Spring Security.

    After a couple of hours remember-me cookie start created. But if I close browser or stop server remember-me cookie disappear.

    Maybe someone can suggest some solution or reason why this happening.

    Please, help 🙂

    Best regards, Alex.

  4. Hello Mkyong,

    Did just what you exp?ained, but using spring-security 4.0.1.RELEASE

    Implemented PersistentTokenRepository on a class, passed it as the repo, could log in, but never got a login by remember-me

    When restart tomcat and the browser (to test remember-me), i can see the data being updated, but i always get a 403. Any ideas?!

  5. Hi Mkyong, Am using mybatis and all the queries are written in service class. Also I have to use custom tables with custom JSP. Please advice how to do it ?

  6. Thank you MKYong, This helped me a lot. But the “targetUrl” in always null when I try to log in for update. After login for update I am not redirected to the targetUrl .

  7. If you are downloading the project zip please update your pom.xml scope to provided
    it is provider in xml file which causes classpath error

  8. Hi Mkyong, I have problem when implementing this to my project. That I currently have no datasource on my securityConfig.java (I use userDetailService as my dataSource on authentication system) and JdbcTokenRepositoryImpl didn’t have SetDataSource properties. Can you help me?
    as I use annotation type and Neo4j as my database

    Thanks 🙂

  9. Hello Mr Mkyong

    Gret job you are doing here, you help a lot of us. Thank you so much !

    I encounter a litte problem, the part “8.4” doesn’t seem to work with me, when I restard the application and remove the browser’s session and I try to access the login page again, it gives me the login not like you said It will remember me and direct me to the admin page.

    What’s wrong ? please help me.

  10. Hi MKyong . I test your code,It works fine with IE 11,while not well with firefox 31.0.
    With firefox ,the cookies and password is stored ,but every time I request admin url,it shows login by username / password,it seemed isRememberMe() not working with firefox . Does we have to make some adapt for different browsers ? can you please check it and help .

  11. Is there a way I can delete only a specific series? When the user logs in from different devices then decides to log out from one of them, Spring automatically removes all of his tokens from the DB.

  12. Hi Mkyong, great job. In which part of the code do you store a row in the persistent_logins table? and is there any code for “forgot password?” function with spring security?? thanks!

    1. Normally, you don’t need to handle the “persistent_login” manually, review step #9, spring’s classes. In remember-me tag, if data-source-ref is specified, “Persistent Token Approach” will be used.

      See Spring’s PersistentTokenBasedRememberMeServices.

      In Spring Security, there’s no ready solution for “Forgot password”. But it’s easy to implement, the standard practice should be send a validation link to user email, and redirect user to a page to key in new password again.

Leave a Comment

Your email address will not be published. Required fields are marked *