How to manage guest sessions in Spring Boot

时光总嘲笑我的痴心妄想 提交于 2021-02-11 14:02:28

问题


I have a Spring Boot application which is always on guest mode. No login is used. The problem is that the same instance of the application is always used. If the shopping cart is filled with products its still the same when I open it from another browser or device.

How can I resolve this? Do I need to use Spring Security?


回答1:


You can add spring security with permit all, no login, and it will manage your session automatically for each guest user, and will automatically add a user header JSESSIONID.

And you can tell spring to always create a user session in your web security config:

protected void configure(HttpSecurity http) throws Exception {

    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS)

and if in future you will implement user authentication, you can easily limit maximum session/user by setting .maximumSessions() .



来源:https://stackoverflow.com/questions/51045564/how-to-manage-guest-sessions-in-spring-boot

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