Search code examples
springspring-securityspring-session

What is the function of Spring Session?


A simple question, what is the use of Spring session where I can do a login with session using spring security? What feature can spring session offer?


Solution

  • To put it simple, Spring Session project provides infrastructure for managing user's session.

    Most notably, this includes replacing the HttpSession implementation provided by your Servlet container (e.g. Tomcat) with an implementation provided by Spring Session which is then persisted using SessionRepository implementation of your choice (Redis, Gemfire, Hazelcast, JDBC, Mongo are supported backends in current 1.2.0.RELEASE). This ensures your sessions are stored in container/platform agnostic way and makes session clustering very easy.

    Additionally, Spring Session provides some other nice features such as:

    • configurable strategies for correlating user's requests with a session (either cookie or HTTP request header based)
    • support for multiple sessions in a single browser instance
    • WebSocket integration, meaning the HttpSession is kept alive when consuming only WebSocket
    • ability to retrieve all the sessions for a given user

    For more information please take a look at Spring Session's user manual as it contains detailed guides which describe the most common use cases.