From e2a7b71cf33a151e4d6a30ba471a97ee1d8a9613 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 19 May 2017 14:00:42 +0200 Subject: [PATCH] KEYCLOAK-4939 ConcurrentLoginTest broken in latest master --- .../infinispan/AuthenticatedClientSessionAdapter.java | 4 ---- .../infinispan/InfinispanUserSessionProvider.java | 8 +++----- .../models/sessions/infinispan/UserSessionAdapter.java | 7 ++----- .../sessions/infinispan/entities/UserSessionEntity.java | 2 +- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/AuthenticatedClientSessionAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/AuthenticatedClientSessionAdapter.java index 13352dfcab..7772bc20f2 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/AuthenticatedClientSessionAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/AuthenticatedClientSessionAdapter.java @@ -69,10 +69,6 @@ public class AuthenticatedClientSessionAdapter implements AuthenticatedClientSes } } else { this.userSession = (UserSessionAdapter) userSession; - - if (sessionEntity.getAuthenticatedClientSessions() == null) { - sessionEntity.setAuthenticatedClientSessions(new HashMap<>()); - } sessionEntity.getAuthenticatedClientSessions().put(clientUUID, entity); update(); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java index 0e50a73d3d..0476698719 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java @@ -53,6 +53,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -518,7 +519,8 @@ public class InfinispanUserSessionProvider implements UserSessionProvider { entity.setBrokerUserId(userSession.getBrokerUserId()); entity.setIpAddress(userSession.getIpAddress()); entity.setLoginUsername(userSession.getLoginUsername()); - entity.setNotes(userSession.getNotes()); + entity.setNotes(userSession.getNotes()== null ? new ConcurrentHashMap<>() : userSession.getNotes()); + entity.setAuthenticatedClientSessions(new ConcurrentHashMap<>()); entity.setRememberMe(userSession.isRememberMe()); entity.setState(userSession.getState()); entity.setUser(userSession.getUser().getId()); @@ -555,10 +557,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider { entity.setTimestamp(clientSession.getTimestamp()); Map clientSessions = importedUserSession.getEntity().getAuthenticatedClientSessions(); - if (clientSessions == null) { - clientSessions = new HashMap<>(); - importedUserSession.getEntity().setAuthenticatedClientSessions(clientSessions); - } clientSessions.put(clientSession.getClient().getId(), entity); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionAdapter.java index 8ab15f7a0e..f35dea974a 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionAdapter.java @@ -159,9 +159,6 @@ public class UserSessionAdapter implements UserSessionModel { @Override public void setNote(String name, String value) { - if (entity.getNotes() == null) { - entity.setNotes(new ConcurrentHashMap<>()); - } if (value == null) { if (entity.getNotes().containsKey(name)) { removeNote(name); @@ -201,8 +198,8 @@ public class UserSessionAdapter implements UserSessionModel { provider.updateSessionEntity(entity, realm, user, loginUsername, ipAddress, authMethod, rememberMe, brokerSessionId, brokerUserId); entity.setState(null); - entity.setNotes(null); - entity.setAuthenticatedClientSessions(null); + entity.getNotes().clear(); + entity.getAuthenticatedClientSessions().clear(); update(); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/UserSessionEntity.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/UserSessionEntity.java index 54d182f0d8..3c4746d846 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/UserSessionEntity.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/UserSessionEntity.java @@ -50,7 +50,7 @@ public class UserSessionEntity extends SessionEntity { private Map notes = new ConcurrentHashMap<>(); - private Map authenticatedClientSessions; + private Map authenticatedClientSessions = new ConcurrentHashMap<>(); public String getUser() { return user;