开发者

How to introduce 'Remember me' checkbox to existing project with Spring Security?

开发者 https://www.devze.com 2022-12-29 00:54 出处:网络
I have a pretty standard project with Spring Security. I have a login form and I need to add \'Remember me\' checkbox there. How can 开发者_开发知识库I do that?

I have a pretty standard project with Spring Security.

I have a login form and I need to add 'Remember me' checkbox there. How can 开发者_开发知识库I do that?

I can provide some code if necessary.


I think the below links will be very useful,

  • Remember-Me Authentication
  • Configuring Spring Security Form Login with Remember-Me Enabled
  • 5 Minute Guide to Spring Security


So this is a complete WAG - but it's how I would do it, at least initially.

I would override the Spring SecurityContextPersistenceFilter so that it only saves the Authentication details (i.e. the SecurityContext) if that box is checked (you would know this by some attribute you included when you POST the Form for login). You could also, possibly, create a new Cookie if the box is checked and check for the existence of said Cookie before you try Authentication - if the cookie exists it contains the UserDetails and will authenticate, otherwise redirect to the login page.


Here is a tutorial from mkyong that is good.

0

精彩评论

暂无评论...
验证码 换一张
取 消