How to store spring security session information in redis?

时光怂恿深爱的人放手 提交于 2019-12-05 11:35:58

All you need to do is to implement a

  • SecurityContextRepository that handles security context storage to reds
  • Eventually a custom filter that retrieves/ stores session information (GenericFilterBean)

I think it is possible to just give the standard filter a different repository, but I am not sure, I needed my own implementation anyway...

Store session in a redis is out-of the box functionality now

http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession.html

You need to configure remember-me feature of Spring Security.

Remember-me or persistent-login authentication refers to web sites being able to remember the identity of a principal between sessions. This is typically accomplished by sending a cookie to the browser, with the cookie being detected during future sessions and causing automated login to take place. Spring Security provides the necessary hooks for these operations to take place, and has two concrete remember-me implementations. One uses hashing to preserve the security of cookie-based tokens and the other uses a database or other persistent storage mechanism to store the generated tokens.

More information available in Spring Security documentation: http://static.springsource.org/spring-security/site/docs/3.1.x/reference/remember-me.html

You can use out of box implementations or inject your own (aforementioned redis).

As Luke Taylor said, Tomcat's default action is serialize/deserialize sessions on container restart. Here

pathname attribute of standard manager is the name of the serialization file. If you dont specify a path name attirbute the default is SESSIONS.SER If you dont want to have sesssions back when restarted, you need to specify it as empty string value..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!