简体   繁体   English

如何在Spring Boot中管理访客会话

[英]How to manage guest sessions in Spring Boot

I have a Spring Boot application which is always on guest mode. 我有一个始终处于访客模式的Spring Boot应用程序。 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? 我需要使用Spring Security吗?

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. 您可以添加“全部允许,无需登录”来添加spring security,它将为每个来宾用户自动管理您的会话,并自动添加用户标头JSESSIONID。

And you can tell spring to always create a user session in your web security config: 您可以告诉spring始终在您的Web安全配置中创建用户会话:

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() . 如果将来要实现用户身份验证,则可以通过设置.maximumSessions()轻松限制最大会话/用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM