From 829e12b85723b8cfbd5c36bf53613744660be2cd Mon Sep 17 00:00:00 2001 From: Pedro Ruivo Date: Wed, 26 Jun 2024 22:17:59 +0100 Subject: [PATCH] Incorrect order when instantiate ClientRemovedEvent * Fix incorrect order in ClientRemovedEvent constructor * Do not send an event if the events list is empty Closes #30840 Signed-off-by: Pedro Ruivo --- .../cluster/infinispan/InfinispanNotificationsManager.java | 3 +++ .../infinispan/remote/RemoteInfinispanNotificationManager.java | 3 +++ .../models/cache/infinispan/events/ClientRemovedEvent.java | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java index 12fca1fa94..a62c0fead2 100644 --- a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java +++ b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/InfinispanNotificationsManager.java @@ -141,6 +141,9 @@ public class InfinispanNotificationsManager { void notify(String taskKey, Collection events, boolean ignoreSender, ClusterProvider.DCNotify dcNotify) { + if (events == null || events.isEmpty()) { + return; + } var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events, myAddress, mySite, dcNotify, ignoreSender); String eventKey = UUID.randomUUID().toString(); diff --git a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/remote/RemoteInfinispanNotificationManager.java b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/remote/RemoteInfinispanNotificationManager.java index 5f3399d88f..53b4d0a52c 100644 --- a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/remote/RemoteInfinispanNotificationManager.java +++ b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/remote/RemoteInfinispanNotificationManager.java @@ -85,6 +85,9 @@ public class RemoteInfinispanNotificationManager { } public void notify(String taskKey, Collection events, boolean ignoreSender, DCNotify dcNotify) { + if (events == null || events.isEmpty()) { + return; + } var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events, topologyInfo.getMyNodeName(), topologyInfo.getMySiteName(), dcNotify, ignoreSender); var eventKey = UUID.randomUUID().toString(); diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientRemovedEvent.java index 77d3217374..5951476ffb 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientRemovedEvent.java @@ -52,7 +52,7 @@ public class ClientRemovedEvent extends BaseClientEvent { public static ClientRemovedEvent create(ClientModel client) { var clientRoles = client.getRolesStream().collect(Collectors.toMap(RoleModel::getId, RoleModel::getName)); - return new ClientRemovedEvent(client.getId(), client.getClientId(), client.getRealm().getId(), clientRoles); + return new ClientRemovedEvent(client.getId(), client.getRealm().getId(), client.getClientId(), clientRoles); }