mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Update UserAuthenticationFilter.java
This commit is contained in:
parent
3bb1bfa399
commit
7222e992da
@ -71,6 +71,7 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
sessionPersistentRegistry.getAllSessions(username, false);
|
sessionPersistentRegistry.getAllSessions(username, false);
|
||||||
|
|
||||||
int userSessions = allSessions.size();
|
int userSessions = allSessions.size();
|
||||||
|
int maxUserSessions = sessionPersistentRegistry.getMaxUserSessions();
|
||||||
|
|
||||||
HttpSession session = request.getSession(false);
|
HttpSession session = request.getSession(false);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
@ -79,13 +80,14 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
}
|
}
|
||||||
String sessionId = session.getId();
|
String sessionId = session.getId();
|
||||||
|
|
||||||
if (allSessions.size() > 2) {
|
if (userSessions > maxUserSessions) {
|
||||||
// Sortiere nach letzter Aktivität – älteste zuerst
|
// Sortiere nach letzter Aktivität – älteste zuerst
|
||||||
List<SessionInformation> sortedSessions =
|
List<SessionInformation> sortedSessions =
|
||||||
allSessions.stream()
|
allSessions.stream()
|
||||||
.sorted(Comparator.comparing(SessionInformation::getLastRequest))
|
.sorted(Comparator.comparing(SessionInformation::getLastRequest))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
int sessionsToExpire = allSessions.size() - 2;
|
int sessionsToExpire = userSessions - maxUserSessions;
|
||||||
|
log.info("Expire {} old sessions", sessionsToExpire);
|
||||||
for (int i = 0; i < sessionsToExpire; i++) {
|
for (int i = 0; i < sessionsToExpire; i++) {
|
||||||
SessionInformation oldSession = sortedSessions.get(i);
|
SessionInformation oldSession = sortedSessions.get(i);
|
||||||
if (!sessionId.equals(oldSession.getSessionId())) {
|
if (!sessionId.equals(oldSession.getSessionId())) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user