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 85ace35908..a7c8c31ec4 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 @@ -478,9 +478,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider { void attachSession(UserSessionAdapter userSession, ClientSessionModel clientSession) { UserSessionEntity entity = userSession.getEntity(); String clientSessionId = clientSession.getId(); - if (entity.getClientSessions() == null) { - entity.setClientSessions(new HashSet()); - } if (!entity.getClientSessions().contains(clientSessionId)) { entity.getClientSessions().add(clientSessionId); userSession.update(); @@ -513,9 +510,6 @@ public class InfinispanUserSessionProvider implements UserSessionProvider { String clientSessionId = clientSession.getId(); if (entity.getClientSessions() != null && entity.getClientSessions().contains(clientSessionId)) { entity.getClientSessions().remove(clientSessionId); - if (entity.getClientSessions().isEmpty()) { - entity.setClientSessions(null); - } userSession.update(); } } 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 446fe82505..bf1e6fd391 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 @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * @author Stian Thorgersen @@ -121,7 +122,13 @@ public class UserSessionAdapter implements UserSessionModel { @Override public void setNote(String name, String value) { if (entity.getNotes() == null) { - entity.setNotes(new HashMap()); + entity.setNotes(new ConcurrentHashMap<>()); + } + if (value == null) { + if (entity.getNotes().containsKey(name)) { + removeNote(name); + } + return; } entity.getNotes().put(name, value); 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 5c538fc514..538babfa4d 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 @@ -21,6 +21,8 @@ import org.keycloak.models.UserSessionModel; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; /** * @author Stian Thorgersen @@ -44,11 +46,11 @@ public class UserSessionEntity extends SessionEntity { private int lastSessionRefresh; - private Set clientSessions; + private Set clientSessions = new CopyOnWriteArraySet<>(); private UserSessionModel.State state; - private Map notes; + private Map notes = new ConcurrentHashMap<>(); public String getUser() { return user; @@ -110,10 +112,6 @@ public class UserSessionEntity extends SessionEntity { return clientSessions; } - public void setClientSessions(Set clientSessions) { - this.clientSessions = clientSessions; - } - public Map getNotes() { return notes; }