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 13352dfcabb0..7772bc20f259 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 void setUserSession(UserSessionModel userSession) { } } 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 0e50a73d3d0b..0476698719a3 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.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 UserSessionAdapter importUserSession(UserSessionModel userSession, boolea 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 @@ private AuthenticatedClientSessionAdapter importClientSession(UserSessionAdapter 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 8ab15f7a0e7a..f35dea974a78 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 String getNote(String name) { @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 void restartSession(RealmModel realm, UserModel user, String loginUsernam 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 54d182f0d85e..3c4746d846f1 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;