Java 使用 Spring Boot 进行会话管理?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42043656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:53:06  来源:igfitidea点击:

Session management with Spring Boot?

javaspringspring-mvcauthentication

提问by Jenna Maiz

I want to set up session management and authentication with Spring Boot. Specifically, when the user logs into my web application, they should be able to call my REST API to get data. Furthermore, after a certain period of time, they should be automatically logged out of the system at which point any REST calls should also fail. How can I accomplish this with Spring Boot ?

我想使用 Spring Boot 设置会话管理和身份验证。具体来说,当用户登录我的 Web 应用程序时,他们应该能够调用我的 REST API 来获取数据。此外,在一段时间后,它们应该会自动从系统中注销,此时任何 REST 调用也应该失败。如何使用 Spring Boot 完成此操作?

回答by Barath

You can make use of Spring Sessionworks well with spring boot

您可以利用Spring Session与 spring boot 配合使用

Docs :http://docs.spring.io/spring-session/docs/current/reference/html5/

文档:http: //docs.spring.io/spring-session/docs/current/reference/html5/

Spring Session provides an API and implementations for managing a user's session information. It also provides transparent integration with:

HttpSession- allows replacing the HttpSession in an application container (i.e. Tomcat) neutral way. Additional features include:

Clustered Sessions- Spring Session makes it trivial to support clustered sessions without being tied to an application container specific solution.

Multiple Browser Sessions- Spring Session supports managing multiple users' sessions in a single browser instance (i.e. multiple authenticated accounts similar to Google).

RESTful APIs- Spring Session allows providing session ids in headers to work with RESTful APIs

Spring Session 提供了用于管理用户会话信息的 API 和实现。它还提供与以下各项的透明集成:

HttpSession- 允许以应用程序容器(即 Tomcat)中立的方式替换 HttpSession。附加功能包括:

集群会话- Spring Session 使得支持集群会话变得微不足道,而无需绑定到特定于应用程序容器的解决方案。

多个浏览器会话- Spring Session 支持在单个浏览器实例中管理多个用户的会话(即类似于 Google 的多个经过身份验证的帐户)。

RESTful APIs- Spring Session 允许在标头中提供会话 ID 以使用 RESTful APIs