当前位置:网站首页>session management
session management
2022-07-19 14:57:00 【Leisurely summer】
Spring Security It can be done with Spring Session Library with the use of , You only need to do some simple configuration to realize some functions , Such as ( Session expiration, 、 Only one account can be online at the same time 、 colony session etc. )
1、 session time out
To configure session Session timeout , The default is 30 minute , however Spring Boot The session timeout in is at least 60 second
#session Set up
# To configure session Timeout time
server.servlet.session.timeout=60
When session After a timeout , By default, jump to the login page ( Default mode )
Custom Settings session Address after timeout
Set up session Management and post failure jump address
http.sessionManagement() // Set up session management
.invalidSessionUrl("/toLoginPage") // session Invalid jump path , The default is the login page
2、 concurrency control
Concurrency control refers to the number of online users of the same account at the same time , If the number of simultaneous online accounts of the same account is set to 1 Express , This account can only have one valid login at a time , If the same account is logged in elsewhere , Then expire the last login session , That is, the later login will kick out the previous login
2.1、 Modify timeout
#session Set up
# To configure session Timeout time
server.servlet.session.timeout=600
2.2、 Set the maximum number of sessions
http.sessionManagement() // Set up session management
.invalidSessionUrl("/toLoginPage") // session The path to jump after failure
.maximumSessions(1)// session Maximum number of sessions 1 Represents that only one user can log in at a time
.maxSessionsPreventsLogin(true) // Maximum number of sessions reached , Stop logging in
.expiredUrl("/toLoginPage"); // session The path to jump after expiration 2.3、 Prevent users from logging in a second time
sessionManagement You can also configure maxSessionsPreventsLogin:boolean value , When reach maximumSessions Block login when setting the maximum number of sessions .
3、 colony session
In the actual scenario, a service will have at least two servers providing services , There will be a in front of the server nginx Load balancing , User access nginx,nginx Then decide which server to access . When a service goes down , Another server can also continue to provide services , Guarantee uninterrupted service . If we were to session Save in Web Containers ( such as tomcat) in , If a user is assigned to the server for the first time 1 You need to log in , When some access is suddenly assigned to server 2 , Because there is no user login session on server 1 on server 2 session Information , Server 2 will also let users log in again , If the user has logged in, it will feel abnormal .

The idea to solve this problem is that the session information logged in by the user can no longer be saved to Web Server , Instead, save to a separate library (redis、mongodb、jdbc etc. ) in , All servers access the same library , Get the user's information from the same library session Information , If the user logs in on the server , Save the session information to the library , The user's next request is assigned to server 2 , Server 2 checks from the Library session Does it already exist , If it exists, you don't have to log in anymore , You can access the service directly .

3.1、 Citation depends on
<!-- be based on redis Realization session share -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>3.2、 Set up session Storage type
# Use redis share session
spring.session.store-type=redis
3.3、 test
- Use one of these services to log in http://localhost:8080/login
- Use another service to access any interface , Then you can access directly without logging in again
边栏推荐
- Code runner for vs code, with more than 40million downloads! Support more than 50 languages
- Behind the high salary of programmers' operation and maintenance
- Preview of authtalk phase I | comprehensive dismantling of multi tenant solutions
- Authing practice | unified management solution for manufacturing identity authentication
- 国内顶尖专家集聚广州,探讨健康医疗数据安全应用
- DMA方式的特点
- Force deduction 912 sorting array notes
- Database SQL Server
- Use of token in ogg
- The bill module of freeswitch
猜你喜欢

Cilium & Hubble

Redis 与 Mysql 的数据一致性

Sliding window maximum problem

LabVIEW uses multithreading. Will the program run faster

Classes abstraites et dérivées

The first step of agile: turn "iteration" into "sprint" and start!

Preview of authtalk phase I | comprehensive dismantling of multi tenant solutions

CF 807 E. mark and Professor Koro (weight segment tree)

dba

MySQL CPU使用率飙升,如何定位是被谁占用了
随机推荐
1. Basic concepts of DBMS
长安链学习研究-存储分析wal机制
ospf-LSA
Classification of blocks
【MQTT从入门到提高系列 | 06】MQTT3.1.1之SUBSCRIBE订阅工作流
ORA-00054
现在网上办理基金开户,身份证信息安全吗?
3438. 数制转换
天勤第九章课后习题代码
MySQL index (II)
009 execution sequence of SQL statement of interview questions
csrf防护机制
【MQTT从入门到提高系列 | 07】MQTT3.1.1之链路保活及断开
Explain the operation of C language file in detail
JVM常用调优配置参数
[Axi] interpret the additional signals of the Axi protocol (QoS signal, region signal, and user signal)
滑动窗口最大值问题
Compositionapi component development paradigm
SQL wrong questions set of Niuke brush questions
C - usage of this