Update UserAuthenticationFilter.java

This commit is contained in:
Ludy87 2025-03-24 00:50:32 +01:00
parent 3bb1bfa399
commit 7222e992da
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -71,6 +71,7 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
sessionPersistentRegistry.getAllSessions(username, false);
int userSessions = allSessions.size();
int maxUserSessions = sessionPersistentRegistry.getMaxUserSessions();
HttpSession session = request.getSession(false);
if (session == null) {
@ -79,13 +80,14 @@ public class UserAuthenticationFilter extends OncePerRequestFilter {
}
String sessionId = session.getId();
if (allSessions.size() > 2) {
if (userSessions > maxUserSessions) {
// Sortiere nach letzter Aktivität älteste zuerst
List<SessionInformation> sortedSessions =
allSessions.stream()
.sorted(Comparator.comparing(SessionInformation::getLastRequest))
.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++) {
SessionInformation oldSession = sortedSessions.get(i);
if (!sessionId.equals(oldSession.getSessionId())) {