Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,26 @@ These options were deprecated and were only relevant when using volatile user se
With persistent user sessions enabled (the default since Keycloak 26), offline sessions are managed in the database and these lifespan override options have no effect.

If you have these options in your configuration, remove them before upgrading to Keycloak 27.

=== ClusterProvider cross-DC notification API removed
// https://github.com/keycloak/keycloak/issues/39047
Comment thread
ahus1 marked this conversation as resolved.
Resolved

The deprecated cross-datacenter notification API in `ClusterProvider` has been removed.
These APIs were deprecated in Keycloak 26.3 when the `cache-embedded-remote-store` feature was removed.

The following have been removed:

* `ClusterProvider.DCNotify` enum
* `ClusterProvider.notify(String, ClusterEvent, boolean, DCNotify)` method
* `ClusterProvider.notify(String, Collection<? extends ClusterEvent>, boolean, DCNotify)` method
* `AuthenticationSessionProvider.updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId, Map<String, String>)` method

The remaining `notify()` methods in `ClusterProvider` are now abstract and notify all datacenters (`ALL_DCS` semantics).
Third-party `ClusterProvider` implementations in `server-spi-private`, if any exist, must implement these methods directly instead of implementing the deprecated `DCNotify` variants.

Multi-site deployments using external Infinispan are unaffected, as they never used the `DCNotify` parameter.
All current callers already use the non-deprecated `notify()` methods which default to `ALL_DCS` semantics.

The internal Infinispan classes that only supported this API have been removed as well.
This includes the `AuthenticationSessionAuthNoteUpdateEvent` cluster event, the site-related fields of `WrapperClusterEvent`, and the `siteId` field of `SessionClusterEvent`.
These classes are not part of the supported SPI.
Original file line number Diff line number Diff line change
Expand Up @@ -98,44 +98,27 @@ public void registerListener(String taskKey, ClusterListener task) {
delegate.registerListener(taskKey, task);
}

@Override
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender, DCNotify dcNotify) {
delegate.notify(taskKey, event, ignoreSender, dcNotify);
if (dcNotify != DCNotify.LOCAL_DC_ONLY) {
persistToDatabase(taskKey, Collections.singleton(event), ignoreSender, dcNotify);
}
}

@Override
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender) {
delegate.notify(taskKey, event, ignoreSender);
persistToDatabase(taskKey, Collections.singleton(event), ignoreSender, DCNotify.ALL_DCS);
}

@Override
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, DCNotify dcNotify) {
delegate.notify(taskKey, events, ignoreSender, dcNotify);
if (dcNotify != DCNotify.LOCAL_DC_ONLY) {
persistToDatabase(taskKey, events, ignoreSender, dcNotify);
}
persistToDatabase(taskKey, Collections.singleton(event), ignoreSender);
}

@Override
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) {
delegate.notify(taskKey, events, ignoreSender);
persistToDatabase(taskKey, events, ignoreSender, DCNotify.ALL_DCS);
persistToDatabase(taskKey, events, ignoreSender);
}

private void persistToDatabase(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, DCNotify dcNotify) {
private void persistToDatabase(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) {
if (events == null || events.isEmpty() || nodeInfo.clusterName() == null) {
return;
}

var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events,
// append the cluster name to the node name to avoid situations where the same node name exists in both clusters
nodeInfo.nodeName() + "@" + nodeInfo.clusterName(),
nodeInfo.siteName(),
dcNotify, ignoreSender);
ignoreSender);
byte[] data;
try {
data = marshaller.objectToByteBuffer(wrappedEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,16 @@ public void registerListener(String taskKey, ClusterListener task) {
}

@Override
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender, DCNotify dcNotify) {
notify(taskKey, Collections.singleton(event), ignoreSender, dcNotify);
}

public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) {
notify(taskKey, events, ignoreSender, DCNotify.ALL_DCS);
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender) {
notify(taskKey, Collections.singleton(event), ignoreSender);
}

@Override
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, DCNotify dcNotify) {
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) {
if (events == null || events.isEmpty()) {
return;
}
var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events, nodeInfo.nodeName(), nodeInfo.siteName(), dcNotify, ignoreSender);
var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events, nodeInfo.nodeName(), ignoreSender);

String eventKey = SecretGenerator.getInstance().generateSecureID();

Expand Down Expand Up @@ -250,7 +246,7 @@ private void eventReceived(String key, Object obj) {
}

private void handleWrapperClusterEvent(WrapperClusterEvent event) {
if (event.rejectEvent(nodeInfo.nodeName(), nodeInfo.siteName())) {
if (event.rejectEvent(nodeInfo.nodeName())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,45 @@
import java.util.Objects;

import org.keycloak.cluster.ClusterEvent;
import org.keycloak.cluster.ClusterProvider;
import org.keycloak.marshalling.Marshalling;

import org.infinispan.protostream.WrappedMessage;
import org.infinispan.protostream.annotations.Proto;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
import org.infinispan.protostream.annotations.ProtoReserved;
import org.infinispan.protostream.annotations.ProtoTypeId;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@ProtoTypeId(Marshalling.WRAPPED_CLUSTER_EVENT)
@ProtoReserved(
value = {3, 4},
names = {"senderSite", "siteFilter"}
)
public class WrapperClusterEvent implements ClusterEvent {

@ProtoField(1)
final String eventKey;
@ProtoField(2)
final String senderAddress; // null means invoke everywhere
@ProtoField(3)
final String senderSite; // can be null
@ProtoField(4)
final SiteFilter siteFilter;
private final Collection<? extends ClusterEvent> events;

private WrapperClusterEvent(String eventKey, String senderAddress, String senderSite, SiteFilter siteFilter, Collection<? extends ClusterEvent> events) {
private WrapperClusterEvent(String eventKey, String senderAddress, Collection<? extends ClusterEvent> events) {
this.eventKey = Objects.requireNonNull(eventKey);
this.senderAddress = senderAddress;
this.senderSite = senderSite;
this.siteFilter = Objects.requireNonNull(siteFilter);
this.events = Objects.requireNonNull(events);
}

@ProtoFactory
static WrapperClusterEvent protoFactory(String eventKey, String senderAddress, String senderSite, SiteFilter siteFilter, List<WrappedMessage> eventPS) {
static WrapperClusterEvent protoFactory(String eventKey, String senderAddress, List<WrappedMessage> eventPS) {
var events = eventPS.stream().map(WrappedMessage::getValue).map(ClusterEvent.class::cast).toList();
return new WrapperClusterEvent(eventKey, senderAddress, senderSite, siteFilter, events);
return new WrapperClusterEvent(eventKey, senderAddress, events);
}

public static WrapperClusterEvent wrap(String eventKey, Collection<? extends ClusterEvent> events, String senderAddress, String senderSite, ClusterProvider.DCNotify dcNotify, boolean ignoreSender) {
public static WrapperClusterEvent wrap(String eventKey, Collection<? extends ClusterEvent> events, String senderAddress, boolean ignoreSender) {
senderAddress = ignoreSender ? Objects.requireNonNull(senderAddress) : null;
senderSite = dcNotify == ClusterProvider.DCNotify.ALL_DCS ? null : senderSite;
var siteNotification = switch (dcNotify) {
case ALL_DCS -> SiteFilter.ALL;
case LOCAL_DC_ONLY -> SiteFilter.LOCAL;
case ALL_BUT_LOCAL_DC -> SiteFilter.REMOTE;
};
return new WrapperClusterEvent(eventKey, senderAddress, senderSite, siteNotification, events);
return new WrapperClusterEvent(eventKey, senderAddress, events);
}

@ProtoField(5)
Expand All @@ -85,10 +76,8 @@ public Collection<? extends ClusterEvent> getDelegateEvents() {
return events;
}

public boolean rejectEvent(String mySiteAddress, String mySiteName) {
return (senderAddress != null && senderAddress.equals(mySiteAddress)) ||
(senderSite != null && siteFilter.reject(senderSite, mySiteName));

public boolean rejectEvent(String mySiteAddress) {
return senderAddress != null && senderAddress.equals(mySiteAddress);
}

@Override
Expand All @@ -99,46 +88,19 @@ public boolean equals(Object o) {
WrapperClusterEvent that = (WrapperClusterEvent) o;
return eventKey.equals(that.eventKey) &&
Objects.equals(senderAddress, that.senderAddress) &&
Objects.equals(senderSite, that.senderSite) &&
siteFilter == that.siteFilter &&
events.equals(that.events);
}

@Override
public int hashCode() {
int result = eventKey.hashCode();
result = 31 * result + Objects.hashCode(senderAddress);
result = 31 * result + Objects.hashCode(senderSite);
result = 31 * result + siteFilter.hashCode();
result = 31 * result + events.hashCode();
return result;
}

@Override
public String toString() {
return String.format("WrapperClusterEvent [ eventKey=%s, sender=%s, senderSite=%s, delegateEvents=%s ]", eventKey, senderAddress, senderSite, events);
}

@Proto
@ProtoTypeId(Marshalling.WRAPPED_CLUSTER_EVENT_SITE_FILTER)
public enum SiteFilter {
ALL {
@Override
boolean reject(String senderSite, String mySite) {
return false;
}
}, LOCAL {
@Override
boolean reject(String senderSite, String mySite) {
return !Objects.equals(senderSite, mySite);
}
}, REMOTE {
@Override
boolean reject(String senderSite, String mySite) {
return Objects.equals(senderSite, mySite);
}
};

abstract boolean reject(String senderSite, String mySite);
return String.format("WrapperClusterEvent [ eventKey=%s, sender=%s, delegateEvents=%s ]", eventKey, senderAddress, events);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,13 @@ public void registerListener(String taskKey, ClusterListener task) {
}

@Override
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender, DCNotify dcNotify) {
data.notificationManager().notify(taskKey, Collections.singleton(event), ignoreSender, dcNotify);
public void notify(String taskKey, ClusterEvent event, boolean ignoreSender) {
data.notificationManager().notify(taskKey, Collections.singleton(event), ignoreSender);
}

@Override
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) {
data.notificationManager().notify(taskKey, events, ignoreSender, DCNotify.ALL_DCS);
}

@Override
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, DCNotify dcNotify) {
data.notificationManager().notify(taskKey, events, ignoreSender, dcNotify);
data.notificationManager().notify(taskKey, events, ignoreSender);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import org.keycloak.cluster.ClusterEvent;
import org.keycloak.cluster.ClusterListener;
import org.keycloak.cluster.ClusterProvider.DCNotify;
import org.keycloak.cluster.infinispan.TaskCallback;
import org.keycloak.cluster.infinispan.WrapperClusterEvent;
import org.keycloak.common.util.ConcurrentMultivaluedHashMap;
Expand Down Expand Up @@ -89,11 +88,11 @@ public TaskCallback registerTaskCallback(String taskKey, TaskCallback callback)
return existing != null ? existing : callback;
}

public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender, DCNotify dcNotify) {
public void notify(String taskKey, Collection<? extends ClusterEvent> events, boolean ignoreSender) {
if (events == null || events.isEmpty()) {
return;
}
var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events, nodeInfo.nodeName(), nodeInfo.siteName(), dcNotify, ignoreSender);
var wrappedEvent = WrapperClusterEvent.wrap(taskKey, events, nodeInfo.nodeName(), ignoreSender);

var eventKey = SecretGenerator.getInstance().generateSecureID();

Expand Down Expand Up @@ -168,7 +167,7 @@ private void eventReceived(String key, Object obj) {
return;
}

if (event.rejectEvent(nodeInfo.nodeName(), nodeInfo.siteName())) {
if (event.rejectEvent(nodeInfo.nodeName())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.keycloak.models.cache.infinispan.authorization.stream.InResourcePredicate;
import org.keycloak.models.cache.infinispan.authorization.stream.InResourceServerPredicate;
import org.keycloak.models.cache.infinispan.authorization.stream.InScopePredicate;
import org.keycloak.models.cache.infinispan.events.AuthenticationSessionAuthNoteUpdateEvent;
import org.keycloak.models.cache.infinispan.events.CacheKeyInvalidatedEvent;
import org.keycloak.models.cache.infinispan.events.ClientAddedEvent;
import org.keycloak.models.cache.infinispan.events.ClientRemovedEvent;
Expand Down Expand Up @@ -138,7 +137,6 @@
LockEntry.class,
LockEntryPredicate.class,
WrapperClusterEvent.class,
WrapperClusterEvent.SiteFilter.class,

// keys.infinispan package
PublicKeyStorageInvalidationEvent.class,
Expand Down Expand Up @@ -189,7 +187,6 @@
InRealmPredicate.class,

// models.cache.infinispan.events package
AuthenticationSessionAuthNoteUpdateEvent.class,
CacheKeyInvalidatedEvent.class,
ClientAddedEvent.class,
ClientUpdatedEvent.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* WARNING! ID defined in this class must be unique. If one type is removed, its ID must not be reused. You have been
* warned! The ID identifies the message, and it is stored and used to save space.
* WARNING! The field IDs cannot be reused as well for the same reason.
* WARNING! When a type is removed, keep its ID constant in this class and mark it as removed, so the ID stays visible as taken.
* Reserve the IDs and names of removed fields with {@code @ProtoReserved} on the message class.
* WARNING! Primitive types cannot be null in proto3 syntax (Integer, String). Take that in consideration.
* <p>
* Be Aware of the following default in Proto3 syntax!
Expand Down Expand Up @@ -82,6 +84,7 @@ private Marshalling() {
public static final int LOCK_ENTRY = 65541;
public static final int LOCK_ENTRY_PREDICATE = 65542;
public static final int WRAPPED_CLUSTER_EVENT = 65543;
// type removed in 27, do not reuse this ID
public static final int WRAPPED_CLUSTER_EVENT_SITE_FILTER = 65544;

// keys.infinispan package
Expand All @@ -98,13 +101,15 @@ private Marshalling() {
public static final int SCOPE_REMOVED_EVENT = 65553;

// models.sessions.infinispan.initializer package
// type removed in 26.3, do not reuse this ID
public static final int INITIALIZER_STATE = 65554;

// models.sessions.infinispan.changes package
public static final int SESSION_ENTITY_WRAPPER = 65555;
public static final int REPLACE_FUNCTION = 65656;

// models.sessions.infinispan.changes.sessions package
// type removed in 26.3, do not reuse this ID
public static final int LAST_SESSION_REFRESH_EVENT = 65557;
public static final int SESSION_DATA = 65558;

Expand Down Expand Up @@ -132,6 +137,7 @@ private Marshalling() {
public static final int IN_REALM_PREDICATE = 65573;

// models.cache.infinispan.events package
// type removed in 27, do not reuse this ID
public static final int AUTHENTICATION_SESSION_AUTH_NOTE_UPDATE_EVENT = 65574;
public static final int CLIENT_ADDED_EVENT = 65575;
public static final int CLIENT_UPDATED_EVENT = 65576;
Expand Down
Loading
Loading