I am using Spring security for Authentication and Authorization in my application. I am using Neo4j database as backend and implemented userDetailsService for authentication.
However, whenever my application restarts, user is forced to login once again. To overcome this, i am thinking to store session information in redis database and load the data to Spring security Context whenever application gets started.
Kindly pass on if there are any articles and pointers to implement the same.
I am thinking of following implementation for it, 1) For every successful authentication, store user details and session details in redis. This must be implemented in loadUserByUsername() method of UserDetailsService implementation 2) Remove the data from redis, whenver user logs out, Where can i do this information? Is there any spring security function where i can call this 3) Load all the data from redis to spring security whenever application restarts, again where do i need to write this logic?
Please let me know if i have missed any information.
Redis is perfect for storing sessions. All operations are performed in memory, and so reads and writes will be fast. If you cannot afford losing any sessions, set appendfsync always in your configuration file. With this, Redis guarantees that any write operations are saved to the disk.
Spring Session Data Redis - provides SessionRepository and ReactiveSessionRepository implementation backed by Redis and configuration support. Spring Session JDBC - provides SessionRepository implementation backed by a relational database and configuration support.
This is the SecurityContextPersistenceFilter. The context will be stored according to the strategy HttpSessionSecurityContextRepository by default, which uses the HTTP Session as storage.
When a session is sent to the Redis server by WebSEAL up to 3 keys will be created in the Redis server to represent the session. In a Redis session cache environment, the client browser sends requests to the WebSEAL server cluster, which then interacts with the Redis server for session management.
All you need to do is to implement a
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With