From faf830dc77e3960f73edd6c62a6078540957dfc8 Mon Sep 17 00:00:00 2001 From: Hynek Mlnarik Date: Fri, 20 Oct 2017 14:43:05 +0200 Subject: [PATCH] KEYCLOAK-5688 Externalizers for cluster messages and predicates --- .../infinispan/WrapperClusterEvent.java | 49 +++++++++++++++++ .../PublicKeyStorageInvalidationEvent.java | 37 +++++++++++++ .../events/PolicyRemovedEvent.java | 48 +++++++++++++++++ .../events/PolicyUpdatedEvent.java | 50 +++++++++++++++++- .../events/ResourceRemovedEvent.java | 50 ++++++++++++++++++ .../events/ResourceServerRemovedEvent.java | 38 ++++++++++++++ .../events/ResourceServerUpdatedEvent.java | 36 +++++++++++++ .../events/ResourceUpdatedEvent.java | 50 ++++++++++++++++++ .../events/ScopeRemovedEvent.java | 40 ++++++++++++++ .../events/ScopeUpdatedEvent.java | 40 ++++++++++++++ .../stream/InResourcePredicate.java | 36 +++++++++++++ .../stream/InResourceServerPredicate.java | 36 +++++++++++++ .../stream/InScopePredicate.java | 36 +++++++++++++ ...henticationSessionAuthNoteUpdateEvent.java | 4 +- .../infinispan/events/ClientAddedEvent.java | 40 ++++++++++++++ .../infinispan/events/ClientRemovedEvent.java | 45 ++++++++++++++++ .../events/ClientTemplateEvent.java | 36 +++++++++++++ .../infinispan/events/ClientUpdatedEvent.java | 40 ++++++++++++++ .../infinispan/events/GroupAddedEvent.java | 38 ++++++++++++++ .../infinispan/events/GroupMovedEvent.java | 42 +++++++++++++++ .../infinispan/events/GroupRemovedEvent.java | 40 ++++++++++++++ .../infinispan/events/GroupUpdatedEvent.java | 36 +++++++++++++ .../infinispan/events/RealmRemovedEvent.java | 38 ++++++++++++++ .../infinispan/events/RealmUpdatedEvent.java | 38 ++++++++++++++ .../infinispan/events/RoleAddedEvent.java | 38 ++++++++++++++ .../infinispan/events/RoleRemovedEvent.java | 40 ++++++++++++++ .../infinispan/events/RoleUpdatedEvent.java | 40 ++++++++++++++ .../UserCacheRealmInvalidationEvent.java | 36 +++++++++++++ .../events/UserConsentsUpdatedEvent.java | 36 +++++++++++++ .../UserFederationLinkRemovedEvent.java | 42 +++++++++++++++ .../UserFederationLinkUpdatedEvent.java | 36 +++++++++++++ .../events/UserFullInvalidationEvent.java | 47 +++++++++++++++++ .../infinispan/events/UserUpdatedEvent.java | 42 +++++++++++++++ .../infinispan/stream/GroupListPredicate.java | 36 +++++++++++++ .../infinispan/stream/HasRolePredicate.java | 36 +++++++++++++ .../infinispan/stream/InClientPredicate.java | 36 +++++++++++++ .../infinispan/stream/InRealmPredicate.java | 36 +++++++++++++ .../changes/SessionEntityWrapper.java | 5 +- .../events/ClientRemovedSessionEvent.java | 37 +++++++++++++ .../events/RealmRemovedSessionEvent.java | 37 +++++++++++++ .../RemoveAllUserLoginFailuresEvent.java | 37 +++++++++++++ .../events/RemoveUserSessionsEvent.java | 37 +++++++++++++ .../events/SessionClusterEvent.java | 40 ++++++++++++++ .../AuthenticationSessionPredicate.java | 47 +++++++++++++++-- .../infinispan/stream/SessionPredicate.java | 39 ++++++++++++-- .../stream/UserLoginFailurePredicate.java | 39 ++++++++++++-- .../stream/UserSessionPredicate.java | 52 +++++++++++++++++-- .../infinispan/util/KeycloakMarshallUtil.java | 24 +++++++++ 48 files changed, 1821 insertions(+), 17 deletions(-) diff --git a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/WrapperClusterEvent.java b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/WrapperClusterEvent.java index 0e58275bcc..6cadd95569 100644 --- a/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/WrapperClusterEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/cluster/infinispan/WrapperClusterEvent.java @@ -18,10 +18,17 @@ package org.keycloak.cluster.infinispan; import org.keycloak.cluster.ClusterEvent; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(WrapperClusterEvent.ExternalizerImpl.class) public class WrapperClusterEvent implements ClusterEvent { private String eventKey; @@ -83,4 +90,46 @@ public class WrapperClusterEvent implements ClusterEvent { public String toString() { return String.format("WrapperClusterEvent [ eventKey=%s, sender=%s, senderSite=%s, delegateEvent=%s ]", eventKey, sender, senderSite, delegateEvent.toString()); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, WrapperClusterEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.eventKey, output); + MarshallUtil.marshallString(obj.sender, output); + MarshallUtil.marshallString(obj.senderSite, output); + output.writeBoolean(obj.ignoreSender); + output.writeBoolean(obj.ignoreSenderSite); + + output.writeObject(obj.delegateEvent); + } + + @Override + public WrapperClusterEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public WrapperClusterEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + WrapperClusterEvent res = new WrapperClusterEvent(); + + res.eventKey = MarshallUtil.unmarshallString(input); + res.sender = MarshallUtil.unmarshallString(input); + res.senderSite = MarshallUtil.unmarshallString(input); + res.ignoreSender = input.readBoolean(); + res.ignoreSenderSite = input.readBoolean(); + + res.delegateEvent = (ClusterEvent) input.readObject(); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/keys/infinispan/PublicKeyStorageInvalidationEvent.java b/model/infinispan/src/main/java/org/keycloak/keys/infinispan/PublicKeyStorageInvalidationEvent.java index 1afcf42308..0f292c6208 100644 --- a/model/infinispan/src/main/java/org/keycloak/keys/infinispan/PublicKeyStorageInvalidationEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/keys/infinispan/PublicKeyStorageInvalidationEvent.java @@ -18,10 +18,17 @@ package org.keycloak.keys.infinispan; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(PublicKeyStorageInvalidationEvent.ExternalizerImpl.class) public class PublicKeyStorageInvalidationEvent extends InvalidationEvent { private String cacheKey; @@ -45,4 +52,34 @@ public class PublicKeyStorageInvalidationEvent extends InvalidationEvent { public String toString() { return "PublicKeyStorageInvalidationEvent [ " + cacheKey + " ]"; } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, PublicKeyStorageInvalidationEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.cacheKey, output); + } + + @Override + public PublicKeyStorageInvalidationEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public PublicKeyStorageInvalidationEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + PublicKeyStorageInvalidationEvent res = new PublicKeyStorageInvalidationEvent(); + res.cacheKey = MarshallUtil.unmarshallString(input); + + return res; + } + } + } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyRemovedEvent.java index 4d46f8189e..b8f296d11d 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyRemovedEvent.java @@ -21,10 +21,19 @@ import java.util.Set; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.HashSet; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(PolicyRemovedEvent.ExternalizerImpl.class) public class PolicyRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -59,4 +68,43 @@ public class PolicyRemovedEvent extends InvalidationEvent implements Authorizati public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.policyRemoval(id, name, resources, resourceTypes, scopes, serverId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, PolicyRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.name, output); + KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output); + KeycloakMarshallUtil.writeCollection(obj.resources, KeycloakMarshallUtil.STRING_EXT, output); + KeycloakMarshallUtil.writeCollection(obj.resourceTypes, KeycloakMarshallUtil.STRING_EXT, output); + MarshallUtil.marshallString(obj.serverId, output); + } + + @Override + public PolicyRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public PolicyRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + PolicyRemovedEvent res = new PolicyRemovedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.name = MarshallUtil.unmarshallString(input); + res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.resources = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.resourceTypes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.serverId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyUpdatedEvent.java index d613c57dce..86912fb97c 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/PolicyUpdatedEvent.java @@ -20,16 +20,25 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.HashSet; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(PolicyUpdatedEvent.ExternalizerImpl.class) public class PolicyUpdatedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; private String name; - private static Set resources; + private Set resources; private Set resourceTypes; private Set scopes; private String serverId; @@ -59,4 +68,43 @@ public class PolicyUpdatedEvent extends InvalidationEvent implements Authorizati public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.policyUpdated(id, name, resources, resourceTypes, scopes, serverId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, PolicyUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.name, output); + KeycloakMarshallUtil.writeCollection(obj.resources, KeycloakMarshallUtil.STRING_EXT, output); + KeycloakMarshallUtil.writeCollection(obj.resourceTypes, KeycloakMarshallUtil.STRING_EXT, output); + KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output); + MarshallUtil.marshallString(obj.serverId, output); + } + + @Override + public PolicyUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public PolicyUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + PolicyUpdatedEvent res = new PolicyUpdatedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.name = MarshallUtil.unmarshallString(input); + res.resources = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.resourceTypes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.serverId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceRemovedEvent.java index 15964a6ce3..62432408b5 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceRemovedEvent.java @@ -20,11 +20,20 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.HashSet; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ResourceRemovedEvent.ExternalizerImpl.class) public class ResourceRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -61,4 +70,45 @@ public class ResourceRemovedEvent extends InvalidationEvent implements Authoriza public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.resourceRemoval(id, name, type, uri, owner, scopes, serverId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ResourceRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.name, output); + MarshallUtil.marshallString(obj.type, output); + MarshallUtil.marshallString(obj.uri, output); + MarshallUtil.marshallString(obj.owner, output); + KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output); + MarshallUtil.marshallString(obj.serverId, output); + } + + @Override + public ResourceRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ResourceRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ResourceRemovedEvent res = new ResourceRemovedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.name = MarshallUtil.unmarshallString(input); + res.type = MarshallUtil.unmarshallString(input); + res.uri = MarshallUtil.unmarshallString(input); + res.owner = MarshallUtil.unmarshallString(input); + res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.serverId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerRemovedEvent.java index 74b8d0c26d..ef432eb03d 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerRemovedEvent.java @@ -20,11 +20,18 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ResourceServerRemovedEvent.ExternalizerImpl.class) public class ResourceServerRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -51,4 +58,35 @@ public class ResourceServerRemovedEvent extends InvalidationEvent implements Aut public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.resourceServerRemoval(id, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ResourceServerRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.clientId, output); + } + + @Override + public ResourceServerRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ResourceServerRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ResourceServerRemovedEvent res = new ResourceServerRemovedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.clientId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerUpdatedEvent.java index 1862345887..f46611bd74 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceServerUpdatedEvent.java @@ -20,11 +20,18 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ResourceServerUpdatedEvent.ExternalizerImpl.class) public class ResourceServerUpdatedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -49,4 +56,33 @@ public class ResourceServerUpdatedEvent extends InvalidationEvent implements Aut public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.resourceServerUpdated(id, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ResourceServerUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + } + + @Override + public ResourceServerUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ResourceServerUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ResourceServerUpdatedEvent res = new ResourceServerUpdatedEvent(); + res.id = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceUpdatedEvent.java index 3f85a6d5b0..fcd9987f20 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ResourceUpdatedEvent.java @@ -20,11 +20,20 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.HashSet; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ResourceUpdatedEvent.ExternalizerImpl.class) public class ResourceUpdatedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -61,4 +70,45 @@ public class ResourceUpdatedEvent extends InvalidationEvent implements Authoriza public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.resourceUpdated(id, name, type, uri, scopes, serverId, owner, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ResourceUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.name, output); + MarshallUtil.marshallString(obj.type, output); + MarshallUtil.marshallString(obj.uri, output); + KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output); + MarshallUtil.marshallString(obj.serverId, output); + MarshallUtil.marshallString(obj.owner, output); + } + + @Override + public ResourceUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ResourceUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ResourceUpdatedEvent res = new ResourceUpdatedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.name = MarshallUtil.unmarshallString(input); + res.type = MarshallUtil.unmarshallString(input); + res.uri = MarshallUtil.unmarshallString(input); + res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new); + res.serverId = MarshallUtil.unmarshallString(input); + res.owner = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeRemovedEvent.java index eb2747c7a4..370354ead8 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeRemovedEvent.java @@ -20,11 +20,18 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ScopeRemovedEvent.ExternalizerImpl.class) public class ScopeRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -53,4 +60,37 @@ public class ScopeRemovedEvent extends InvalidationEvent implements Authorizatio public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.scopeRemoval(id, name, serverId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ScopeRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.name, output); + MarshallUtil.marshallString(obj.serverId, output); + } + + @Override + public ScopeRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ScopeRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ScopeRemovedEvent res = new ScopeRemovedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.name = MarshallUtil.unmarshallString(input); + res.serverId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeUpdatedEvent.java index 9fbbd443bb..f714b46a70 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/events/ScopeUpdatedEvent.java @@ -20,11 +20,18 @@ package org.keycloak.models.cache.infinispan.authorization.events; import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager; import org.keycloak.models.cache.infinispan.events.InvalidationEvent; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Set; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ScopeUpdatedEvent.ExternalizerImpl.class) public class ScopeUpdatedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent { private String id; @@ -53,4 +60,37 @@ public class ScopeUpdatedEvent extends InvalidationEvent implements Authorizatio public void addInvalidations(StoreFactoryCacheManager cache, Set invalidations) { cache.scopeUpdated(id, name, serverId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ScopeUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.id, output); + MarshallUtil.marshallString(obj.name, output); + MarshallUtil.marshallString(obj.serverId, output); + } + + @Override + public ScopeUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ScopeUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ScopeUpdatedEvent res = new ScopeUpdatedEvent(); + res.id = MarshallUtil.unmarshallString(input); + res.name = MarshallUtil.unmarshallString(input); + res.serverId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourcePredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourcePredicate.java index f72de49c85..b4c7c1c022 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourcePredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourcePredicate.java @@ -22,10 +22,17 @@ import java.util.function.Predicate; import org.keycloak.models.cache.infinispan.authorization.entities.InResource; import org.keycloak.models.cache.infinispan.entities.Revisioned; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Pedro Igor */ +@SerializeWith(InResourcePredicate.ExternalizerImpl.class) public class InResourcePredicate implements Predicate>, Serializable { private String resourceId; @@ -47,4 +54,33 @@ public class InResourcePredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, InResourcePredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.resourceId, output); + } + + @Override + public InResourcePredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public InResourcePredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + InResourcePredicate res = new InResourcePredicate(); + res.resourceId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourceServerPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourceServerPredicate.java index a741303288..2a0b6cf80c 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourceServerPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InResourceServerPredicate.java @@ -3,14 +3,21 @@ package org.keycloak.models.cache.infinispan.authorization.stream; import org.keycloak.models.cache.infinispan.authorization.entities.InResourceServer; import org.keycloak.models.cache.infinispan.entities.Revisioned; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Bill Burke * @version $Revision: 1 $ */ +@SerializeWith(InResourceServerPredicate.ExternalizerImpl.class) public class InResourceServerPredicate implements Predicate>, Serializable { private String serverId; @@ -31,4 +38,33 @@ public class InResourceServerPredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, InResourceServerPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.serverId, output); + } + + @Override + public InResourceServerPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public InResourceServerPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + InResourceServerPredicate res = new InResourceServerPredicate(); + res.serverId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InScopePredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InScopePredicate.java index 8ddf2f373d..1c6bced8c0 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InScopePredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/authorization/stream/InScopePredicate.java @@ -6,11 +6,18 @@ import java.util.function.Predicate; import org.keycloak.models.cache.infinispan.authorization.entities.InScope; import org.keycloak.models.cache.infinispan.entities.Revisioned; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Bill Burke * @version $Revision: 1 $ */ +@SerializeWith(InScopePredicate.ExternalizerImpl.class) public class InScopePredicate implements Predicate>, Serializable { private String scopeId; @@ -31,4 +38,33 @@ public class InScopePredicate implements Predicate return scopeId.equals(((InScope)value).getScopeId()); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, InScopePredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.scopeId, output); + } + + @Override + public InScopePredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public InScopePredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + InScopePredicate res = new InScopePredicate(); + res.scopeId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/AuthenticationSessionAuthNoteUpdateEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/AuthenticationSessionAuthNoteUpdateEvent.java index e56d4a4043..34e22e3277 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/AuthenticationSessionAuthNoteUpdateEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/AuthenticationSessionAuthNoteUpdateEvent.java @@ -70,7 +70,7 @@ public class AuthenticationSessionAuthNoteUpdateEvent implements ClusterEvent { @Override public void writeObject(ObjectOutput output, AuthenticationSessionAuthNoteUpdateEvent value) throws IOException { - output.write(VERSION_1); + output.writeByte(VERSION_1); MarshallUtil.marshallString(value.authSessionId, output); MarshallUtil.marshallMap(value.authNotesFragment, output); @@ -89,7 +89,7 @@ public class AuthenticationSessionAuthNoteUpdateEvent implements ClusterEvent { public AuthenticationSessionAuthNoteUpdateEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { return create( MarshallUtil.unmarshallString(input), - MarshallUtil.unmarshallMap(input, (size) -> new HashMap<>(size)) + MarshallUtil.unmarshallMap(input, HashMap::new) ); } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java index 1b022ca4cf..ae264b0c63 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientAddedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ClientAddedEvent.ExternalizerImpl.class) public class ClientAddedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String clientUuid; @@ -52,4 +59,37 @@ public class ClientAddedEvent extends InvalidationEvent implements RealmCacheInv public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.clientAdded(realmId, clientUuid, clientId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ClientAddedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.clientUuid, output); + MarshallUtil.marshallString(obj.clientId, output); + MarshallUtil.marshallString(obj.realmId, output); + } + + @Override + public ClientAddedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ClientAddedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ClientAddedEvent res = new ClientAddedEvent(); + res.clientUuid = MarshallUtil.unmarshallString(input); + res.clientId = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + + return res; + } + } } 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 2e620db06e..2d4869327d 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 @@ -24,10 +24,19 @@ import java.util.Set; import org.keycloak.models.ClientModel; import org.keycloak.models.RoleModel; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.concurrent.ConcurrentHashMap; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ClientRemovedEvent.ExternalizerImpl.class) public class ClientRemovedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String clientUuid; @@ -71,4 +80,40 @@ public class ClientRemovedEvent extends InvalidationEvent implements RealmCacheI realmCache.roleRemoval(roleId, roleName, clientUuid, invalidations); } } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ClientRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.clientUuid, output); + MarshallUtil.marshallString(obj.clientId, output); + MarshallUtil.marshallString(obj.realmId, output); + KeycloakMarshallUtil.writeMap(obj.clientRoles, KeycloakMarshallUtil.STRING_EXT, KeycloakMarshallUtil.STRING_EXT, output); + } + + @Override + public ClientRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ClientRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ClientRemovedEvent res = new ClientRemovedEvent(); + res.clientUuid = MarshallUtil.unmarshallString(input); + res.clientId = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + res.clientRoles = KeycloakMarshallUtil.readMap(input, KeycloakMarshallUtil.STRING_EXT, KeycloakMarshallUtil.STRING_EXT, + size -> new ConcurrentHashMap<>(size)); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientTemplateEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientTemplateEvent.java index 7bb13a9388..4a49ee63bd 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientTemplateEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientTemplateEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ClientTemplateEvent.ExternalizerImpl.class) public class ClientTemplateEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String clientTemplateId; @@ -49,4 +56,33 @@ public class ClientTemplateEvent extends InvalidationEvent implements RealmCache public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { // Nothing. ID was already invalidated } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ClientTemplateEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.clientTemplateId, output); + } + + @Override + public ClientTemplateEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ClientTemplateEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ClientTemplateEvent res = new ClientTemplateEvent(); + res.clientTemplateId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientUpdatedEvent.java index cc6c263fe0..c66ba49d31 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/ClientUpdatedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ClientUpdatedEvent.ExternalizerImpl.class) public class ClientUpdatedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String clientUuid; @@ -52,4 +59,37 @@ public class ClientUpdatedEvent extends InvalidationEvent implements RealmCacheI public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.clientUpdated(realmId, clientUuid, clientId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ClientUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.clientUuid, output); + MarshallUtil.marshallString(obj.clientId, output); + MarshallUtil.marshallString(obj.realmId, output); + } + + @Override + public ClientUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ClientUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ClientUpdatedEvent res = new ClientUpdatedEvent(); + res.clientUuid = MarshallUtil.unmarshallString(input); + res.clientId = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupAddedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupAddedEvent.java index 77dcf69ad2..5573e61b74 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupAddedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupAddedEvent.java @@ -20,11 +20,18 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * * @author Marek Posolda */ +@SerializeWith(GroupAddedEvent.ExternalizerImpl.class) public class GroupAddedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String groupId; @@ -51,4 +58,35 @@ public class GroupAddedEvent extends InvalidationEvent implements RealmCacheInva public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.groupQueriesInvalidations(realmId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, GroupAddedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.groupId, output); + MarshallUtil.marshallString(obj.realmId, output); + } + + @Override + public GroupAddedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public GroupAddedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + GroupAddedEvent res = new GroupAddedEvent(); + res.groupId = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupMovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupMovedEvent.java index 2f5566aed3..1f977239c7 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupMovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupMovedEvent.java @@ -21,10 +21,17 @@ import java.util.Set; import org.keycloak.models.GroupModel; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(GroupMovedEvent.ExternalizerImpl.class) public class GroupMovedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String groupId; @@ -61,4 +68,39 @@ public class GroupMovedEvent extends InvalidationEvent implements RealmCacheInva invalidations.add(oldParentId); } } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, GroupMovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.groupId, output); + MarshallUtil.marshallString(obj.newParentId, output); + MarshallUtil.marshallString(obj.oldParentId, output); + MarshallUtil.marshallString(obj.realmId, output); + } + + @Override + public GroupMovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public GroupMovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + GroupMovedEvent res = new GroupMovedEvent(); + res.groupId = MarshallUtil.unmarshallString(input); + res.newParentId = MarshallUtil.unmarshallString(input); + res.oldParentId = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupRemovedEvent.java index 37689faca5..bd301f7f73 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupRemovedEvent.java @@ -21,10 +21,17 @@ import java.util.Set; import org.keycloak.models.GroupModel; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(GroupRemovedEvent.ExternalizerImpl.class) public class GroupRemovedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String groupId; @@ -56,4 +63,37 @@ public class GroupRemovedEvent extends InvalidationEvent implements RealmCacheIn invalidations.add(parentId); } } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, GroupRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realmId, output); + MarshallUtil.marshallString(obj.groupId, output); + MarshallUtil.marshallString(obj.parentId, output); + } + + @Override + public GroupRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public GroupRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + GroupRemovedEvent res = new GroupRemovedEvent(); + res.realmId = MarshallUtil.unmarshallString(input); + res.groupId = MarshallUtil.unmarshallString(input); + res.parentId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupUpdatedEvent.java index c59021b446..a7ec69e27c 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/GroupUpdatedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(GroupUpdatedEvent.ExternalizerImpl.class) public class GroupUpdatedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String groupId; @@ -49,4 +56,33 @@ public class GroupUpdatedEvent extends InvalidationEvent implements RealmCacheIn public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { // Nothing. ID already invalidated } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, GroupUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.groupId, output); + } + + @Override + public GroupUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public GroupUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + GroupUpdatedEvent res = new GroupUpdatedEvent(); + res.groupId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmRemovedEvent.java index 355875734f..df5c6b7483 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmRemovedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(RealmRemovedEvent.ExternalizerImpl.class) public class RealmRemovedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String realmId; @@ -50,4 +57,35 @@ public class RealmRemovedEvent extends InvalidationEvent implements RealmCacheIn public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.realmRemoval(realmId, realmName, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RealmRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realmId, output); + MarshallUtil.marshallString(obj.realmName, output); + } + + @Override + public RealmRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RealmRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RealmRemovedEvent res = new RealmRemovedEvent(); + res.realmId = MarshallUtil.unmarshallString(input); + res.realmName = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmUpdatedEvent.java index 624fc6da93..ce3c9c2878 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RealmUpdatedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(RealmUpdatedEvent.ExternalizerImpl.class) public class RealmUpdatedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String realmId; @@ -50,4 +57,35 @@ public class RealmUpdatedEvent extends InvalidationEvent implements RealmCacheIn public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.realmUpdated(realmId, realmName, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RealmUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realmId, output); + MarshallUtil.marshallString(obj.realmName, output); + } + + @Override + public RealmUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RealmUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RealmUpdatedEvent res = new RealmUpdatedEvent(); + res.realmId = MarshallUtil.unmarshallString(input); + res.realmName = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleAddedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleAddedEvent.java index cb393e5be8..fac386f0ea 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleAddedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleAddedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(RoleAddedEvent.ExternalizerImpl.class) public class RoleAddedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String roleId; @@ -50,4 +57,35 @@ public class RoleAddedEvent extends InvalidationEvent implements RealmCacheInval public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.roleAdded(containerId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RoleAddedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.roleId, output); + MarshallUtil.marshallString(obj.containerId, output); + } + + @Override + public RoleAddedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RoleAddedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RoleAddedEvent res = new RoleAddedEvent(); + res.roleId = MarshallUtil.unmarshallString(input); + res.containerId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleRemovedEvent.java index 6137b1bdae..59297e334e 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleRemovedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(RoleRemovedEvent.ExternalizerImpl.class) public class RoleRemovedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String roleId; @@ -52,4 +59,37 @@ public class RoleRemovedEvent extends InvalidationEvent implements RealmCacheInv public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.roleRemoval(roleId, roleName, containerId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RoleRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.roleId, output); + MarshallUtil.marshallString(obj.roleName, output); + MarshallUtil.marshallString(obj.containerId, output); + } + + @Override + public RoleRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RoleRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RoleRemovedEvent res = new RoleRemovedEvent(); + res.roleId = MarshallUtil.unmarshallString(input); + res.roleName = MarshallUtil.unmarshallString(input); + res.containerId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleUpdatedEvent.java index 4b2ae5b2df..c550b704bf 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/RoleUpdatedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.RealmCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(RoleUpdatedEvent.ExternalizerImpl.class) public class RoleUpdatedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent { private String roleId; @@ -52,4 +59,37 @@ public class RoleUpdatedEvent extends InvalidationEvent implements RealmCacheInv public void addInvalidations(RealmCacheManager realmCache, Set invalidations) { realmCache.roleUpdated(containerId, roleName, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RoleUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.roleId, output); + MarshallUtil.marshallString(obj.roleName, output); + MarshallUtil.marshallString(obj.containerId, output); + } + + @Override + public RoleUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RoleUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RoleUpdatedEvent res = new RoleUpdatedEvent(); + res.roleId = MarshallUtil.unmarshallString(input); + res.roleName = MarshallUtil.unmarshallString(input); + res.containerId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserCacheRealmInvalidationEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserCacheRealmInvalidationEvent.java index 39961815d4..2f144d2371 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserCacheRealmInvalidationEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserCacheRealmInvalidationEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.UserCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(UserCacheRealmInvalidationEvent.ExternalizerImpl.class) public class UserCacheRealmInvalidationEvent extends InvalidationEvent implements UserCacheInvalidationEvent { private String realmId; @@ -48,4 +55,33 @@ public class UserCacheRealmInvalidationEvent extends InvalidationEvent implemen public void addInvalidations(UserCacheManager userCache, Set invalidations) { userCache.invalidateRealmUsers(realmId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserCacheRealmInvalidationEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realmId, output); + } + + @Override + public UserCacheRealmInvalidationEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserCacheRealmInvalidationEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserCacheRealmInvalidationEvent res = new UserCacheRealmInvalidationEvent(); + res.realmId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserConsentsUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserConsentsUpdatedEvent.java index 021e84180f..1d4b93d6c2 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserConsentsUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserConsentsUpdatedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.UserCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(UserConsentsUpdatedEvent.ExternalizerImpl.class) public class UserConsentsUpdatedEvent extends InvalidationEvent implements UserCacheInvalidationEvent { private String userId; @@ -48,4 +55,33 @@ public class UserConsentsUpdatedEvent extends InvalidationEvent implements UserC public void addInvalidations(UserCacheManager userCache, Set invalidations) { userCache.consentInvalidation(userId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserConsentsUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.userId, output); + } + + @Override + public UserConsentsUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserConsentsUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserConsentsUpdatedEvent res = new UserConsentsUpdatedEvent(); + res.userId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkRemovedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkRemovedEvent.java index 15704df27e..b75232832f 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkRemovedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkRemovedEvent.java @@ -21,10 +21,17 @@ import java.util.Set; import org.keycloak.models.FederatedIdentityModel; import org.keycloak.models.cache.infinispan.UserCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(UserFederationLinkRemovedEvent.ExternalizerImpl.class) public class UserFederationLinkRemovedEvent extends InvalidationEvent implements UserCacheInvalidationEvent { private String userId; @@ -69,4 +76,39 @@ public class UserFederationLinkRemovedEvent extends InvalidationEvent implements public void addInvalidations(UserCacheManager userCache, Set invalidations) { userCache.federatedIdentityLinkRemovedInvalidation(userId, realmId, identityProviderId, socialUserId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserFederationLinkRemovedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.userId, output); + MarshallUtil.marshallString(obj.realmId, output); + MarshallUtil.marshallString(obj.identityProviderId, output); + MarshallUtil.marshallString(obj.socialUserId, output); + } + + @Override + public UserFederationLinkRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserFederationLinkRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserFederationLinkRemovedEvent res = new UserFederationLinkRemovedEvent(); + res.userId = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + res.identityProviderId = MarshallUtil.unmarshallString(input); + res.socialUserId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkUpdatedEvent.java index 8bbfb41210..692915bffd 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFederationLinkUpdatedEvent.java @@ -19,10 +19,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.UserCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(UserFederationLinkUpdatedEvent.ExternalizerImpl.class) public class UserFederationLinkUpdatedEvent extends InvalidationEvent implements UserCacheInvalidationEvent { private String userId; @@ -47,4 +54,33 @@ public class UserFederationLinkUpdatedEvent extends InvalidationEvent implements public void addInvalidations(UserCacheManager userCache, Set invalidations) { userCache.federatedIdentityLinkUpdatedInvalidation(userId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserFederationLinkUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.userId, output); + } + + @Override + public UserFederationLinkUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserFederationLinkUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserFederationLinkUpdatedEvent res = new UserFederationLinkUpdatedEvent(); + res.userId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFullInvalidationEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFullInvalidationEvent.java index d637ac2f54..ebc4efa71b 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFullInvalidationEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserFullInvalidationEvent.java @@ -24,12 +24,20 @@ import java.util.Set; import org.keycloak.models.FederatedIdentityModel; import org.keycloak.models.cache.infinispan.UserCacheManager; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * Used when user added/removed * * @author Marek Posolda */ +@SerializeWith(UserFullInvalidationEvent.ExternalizerImpl.class) public class UserFullInvalidationEvent extends InvalidationEvent implements UserCacheInvalidationEvent { private String userId; @@ -75,4 +83,43 @@ public class UserFullInvalidationEvent extends InvalidationEvent implements User public void addInvalidations(UserCacheManager userCache, Set invalidations) { userCache.fullUserInvalidation(userId, username, email, realmId, identityFederationEnabled, federatedIdentities, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserFullInvalidationEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.userId, output); + MarshallUtil.marshallString(obj.username, output); + MarshallUtil.marshallString(obj.email, output); + MarshallUtil.marshallString(obj.realmId, output); + output.writeBoolean(obj.identityFederationEnabled); + KeycloakMarshallUtil.writeMap(obj.federatedIdentities, KeycloakMarshallUtil.STRING_EXT, KeycloakMarshallUtil.STRING_EXT, output); + } + + @Override + public UserFullInvalidationEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserFullInvalidationEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserFullInvalidationEvent res = new UserFullInvalidationEvent(); + res.userId = MarshallUtil.unmarshallString(input); + res.username = MarshallUtil.unmarshallString(input); + res.email = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + res.identityFederationEnabled = input.readBoolean(); + res.federatedIdentities = KeycloakMarshallUtil.readMap(input, KeycloakMarshallUtil.STRING_EXT, KeycloakMarshallUtil.STRING_EXT, HashMap::new); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserUpdatedEvent.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserUpdatedEvent.java index 429b4af1dd..0292653697 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserUpdatedEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/events/UserUpdatedEvent.java @@ -20,10 +20,17 @@ package org.keycloak.models.cache.infinispan.events; import java.util.Set; import org.keycloak.models.cache.infinispan.UserCacheManager; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(UserUpdatedEvent.ExternalizerImpl.class) public class UserUpdatedEvent extends InvalidationEvent implements UserCacheInvalidationEvent { private String userId; @@ -54,4 +61,39 @@ public class UserUpdatedEvent extends InvalidationEvent implements UserCacheInva public void addInvalidations(UserCacheManager userCache, Set invalidations) { userCache.userUpdatedInvalidations(userId, username, email, realmId, invalidations); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserUpdatedEvent obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.userId, output); + MarshallUtil.marshallString(obj.username, output); + MarshallUtil.marshallString(obj.email, output); + MarshallUtil.marshallString(obj.realmId, output); + } + + @Override + public UserUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserUpdatedEvent res = new UserUpdatedEvent(); + res.userId = MarshallUtil.unmarshallString(input); + res.username = MarshallUtil.unmarshallString(input); + res.email = MarshallUtil.unmarshallString(input); + res.realmId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/GroupListPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/GroupListPredicate.java index 26562a5a81..c89c44bb74 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/GroupListPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/GroupListPredicate.java @@ -3,14 +3,21 @@ package org.keycloak.models.cache.infinispan.stream; import org.keycloak.models.cache.infinispan.entities.GroupListQuery; import org.keycloak.models.cache.infinispan.entities.Revisioned; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Bill Burke * @version $Revision: 1 $ */ +@SerializeWith(GroupListPredicate.ExternalizerImpl.class) public class GroupListPredicate implements Predicate>, Serializable { private String realm; @@ -33,4 +40,33 @@ public class GroupListPredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, GroupListPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realm, output); + } + + @Override + public GroupListPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public GroupListPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + GroupListPredicate res = new GroupListPredicate(); + res.realm = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/HasRolePredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/HasRolePredicate.java index e0de8e751a..ddb3a64f5b 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/HasRolePredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/HasRolePredicate.java @@ -7,14 +7,21 @@ import org.keycloak.models.cache.infinispan.entities.CachedRole; import org.keycloak.models.cache.infinispan.entities.Revisioned; import org.keycloak.models.cache.infinispan.entities.RoleQuery; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Bill Burke * @version $Revision: 1 $ */ +@SerializeWith(HasRolePredicate.ExternalizerImpl.class) public class HasRolePredicate implements Predicate>, Serializable { private String role; @@ -55,4 +62,33 @@ public class HasRolePredicate implements Predicate } return false; } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, HasRolePredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.role, output); + } + + @Override + public HasRolePredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public HasRolePredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + HasRolePredicate res = new HasRolePredicate(); + res.role = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InClientPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InClientPredicate.java index a582f34f27..3837c71cba 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InClientPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InClientPredicate.java @@ -3,14 +3,21 @@ package org.keycloak.models.cache.infinispan.stream; import org.keycloak.models.cache.infinispan.entities.InClient; import org.keycloak.models.cache.infinispan.entities.Revisioned; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Bill Burke * @version $Revision: 1 $ */ +@SerializeWith(InClientPredicate.ExternalizerImpl.class) public class InClientPredicate implements Predicate>, Serializable { private String clientId; @@ -31,4 +38,33 @@ public class InClientPredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, InClientPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.clientId, output); + } + + @Override + public InClientPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public InClientPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + InClientPredicate res = new InClientPredicate(); + res.clientId = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InRealmPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InRealmPredicate.java index d24a9bd142..7144d613b8 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InRealmPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/stream/InRealmPredicate.java @@ -3,14 +3,21 @@ package org.keycloak.models.cache.infinispan.stream; import org.keycloak.models.cache.infinispan.entities.InRealm; import org.keycloak.models.cache.infinispan.entities.Revisioned; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Bill Burke * @version $Revision: 1 $ */ +@SerializeWith(InRealmPredicate.ExternalizerImpl.class) public class InRealmPredicate implements Predicate>, Serializable { private String realm; @@ -31,4 +38,33 @@ public class InRealmPredicate implements Predicate return realm.equals(((InRealm)value).getRealm()); } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, InRealmPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realm, output); + } + + @Override + public InRealmPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public InRealmPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + InRealmPredicate res = new InRealmPredicate(); + res.realm = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java index 0a3a5bf39b..bb74f4f314 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java @@ -29,6 +29,7 @@ import org.infinispan.commons.marshall.Externalizer; import org.infinispan.commons.marshall.MarshallUtil; import org.infinispan.commons.marshall.SerializeWith; import org.keycloak.models.sessions.infinispan.entities.SessionEntity; +import java.util.HashMap; import org.jboss.logging.Logger; /** @@ -157,7 +158,7 @@ public class SessionEntityWrapper { @Override public void writeObject(ObjectOutput output, SessionEntityWrapper obj) throws IOException { - output.write(VERSION_1); + output.writeByte(VERSION_1); final boolean forTransport = obj.isForTransport(); output.writeBoolean(forTransport); @@ -187,7 +188,7 @@ public class SessionEntityWrapper { return new SessionEntityWrapper(entity); } else { UUID sessionVersion = new UUID(input.readLong(), input.readLong()); - ConcurrentHashMap map = MarshallUtil.unmarshallMap(input, (size) -> new ConcurrentHashMap<>(size)); + HashMap map = MarshallUtil.unmarshallMap(input, HashMap::new); final SessionEntity entity = (SessionEntity) input.readObject(); log.debugf("Found entity locally: %s", entity); return new SessionEntityWrapper(sessionVersion, map, entity); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/ClientRemovedSessionEvent.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/ClientRemovedSessionEvent.java index 8dbad8cc35..63121d7174 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/ClientRemovedSessionEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/ClientRemovedSessionEvent.java @@ -18,10 +18,17 @@ package org.keycloak.models.sessions.infinispan.events; import org.keycloak.models.KeycloakSession; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ +@SerializeWith(ClientRemovedSessionEvent.ExternalizerImpl.class) public class ClientRemovedSessionEvent extends SessionClusterEvent { private String clientUuid; @@ -40,4 +47,34 @@ public class ClientRemovedSessionEvent extends SessionClusterEvent { public String getClientUuid() { return clientUuid; } + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, ClientRemovedSessionEvent obj) throws IOException { + output.writeByte(VERSION_1); + obj.marshallTo(output); + MarshallUtil.marshallString(obj.clientUuid, output); + } + + @Override + public ClientRemovedSessionEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public ClientRemovedSessionEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + ClientRemovedSessionEvent res = new ClientRemovedSessionEvent(); + res.unmarshallFrom(input); + res.clientUuid = MarshallUtil.unmarshallString(input); + + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RealmRemovedSessionEvent.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RealmRemovedSessionEvent.java index 76d6aaf920..011f725c3e 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RealmRemovedSessionEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RealmRemovedSessionEvent.java @@ -17,8 +17,45 @@ package org.keycloak.models.sessions.infinispan.events; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.SerializeWith; + /** * @author Marek Posolda */ +@SerializeWith(RealmRemovedSessionEvent.ExternalizerImpl.class) public class RealmRemovedSessionEvent extends SessionClusterEvent { + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RealmRemovedSessionEvent obj) throws IOException { + output.writeByte(VERSION_1); + + obj.marshallTo(output); + } + + @Override + public RealmRemovedSessionEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RealmRemovedSessionEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RealmRemovedSessionEvent res = new RealmRemovedSessionEvent(); + res.unmarshallFrom(input); + + return res; + } + } + } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveAllUserLoginFailuresEvent.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveAllUserLoginFailuresEvent.java index 7b0f3b7432..5b5a589e9c 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveAllUserLoginFailuresEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveAllUserLoginFailuresEvent.java @@ -17,8 +17,45 @@ package org.keycloak.models.sessions.infinispan.events; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.SerializeWith; + /** * @author Marek Posolda */ +@SerializeWith(RemoveAllUserLoginFailuresEvent.ExternalizerImpl.class) public class RemoveAllUserLoginFailuresEvent extends SessionClusterEvent { + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RemoveAllUserLoginFailuresEvent obj) throws IOException { + output.writeByte(VERSION_1); + + obj.marshallTo(output); + } + + @Override + public RemoveAllUserLoginFailuresEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RemoveAllUserLoginFailuresEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RemoveAllUserLoginFailuresEvent res = new RemoveAllUserLoginFailuresEvent(); + res.unmarshallFrom(input); + + return res; + } + } + } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveUserSessionsEvent.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveUserSessionsEvent.java index 968ff8619c..091d3510c1 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveUserSessionsEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/RemoveUserSessionsEvent.java @@ -17,8 +17,45 @@ package org.keycloak.models.sessions.infinispan.events; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.SerializeWith; + /** * @author Marek Posolda */ +@SerializeWith(RemoveUserSessionsEvent.ExternalizerImpl.class) public class RemoveUserSessionsEvent extends SessionClusterEvent { + + public static class ExternalizerImpl implements Externalizer { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, RemoveUserSessionsEvent obj) throws IOException { + output.writeByte(VERSION_1); + + obj.marshallTo(output); + } + + @Override + public RemoveUserSessionsEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public RemoveUserSessionsEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + RemoveUserSessionsEvent res = new RemoveUserSessionsEvent(); + res.unmarshallFrom(input); + + return res; + } + } + } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/SessionClusterEvent.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/SessionClusterEvent.java index 118eb53526..3b8c4da865 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/SessionClusterEvent.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/events/SessionClusterEvent.java @@ -20,6 +20,10 @@ package org.keycloak.models.sessions.infinispan.events; import org.keycloak.cluster.ClusterEvent; import org.keycloak.models.KeycloakSession; import org.keycloak.models.sessions.infinispan.util.InfinispanUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.MarshallUtil; /** * @author Marek Posolda @@ -78,4 +82,40 @@ public abstract class SessionClusterEvent implements ClusterEvent { String simpleClassName = getClass().getSimpleName(); return String.format("%s [ realmId=%s ]", simpleClassName, realmId); } + + // Infinispan marshalling support for child classes + private static final int VERSION_1 = 1; + + protected void marshallTo(ObjectOutput output) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(realmId, output); + MarshallUtil.marshallString(eventKey, output); + output.writeBoolean(resendingEvent); + MarshallUtil.marshallString(siteId, output); + MarshallUtil.marshallString(nodeId, output); + } + + /** + * Sets the properties of this object from the input stream. + * @param input + * @throws IOException + */ + protected void unmarshallFrom(ObjectInput input) throws IOException { + switch (input.readByte()) { + case VERSION_1: + unmarshallFromVersion1(input); + break; + default: + throw new IOException("Unknown version"); + } + } + + private void unmarshallFromVersion1(ObjectInput input) throws IOException { + this.realmId = MarshallUtil.unmarshallString(input); + this.eventKey = MarshallUtil.unmarshallString(input); + this.resendingEvent = input.readBoolean(); + this.siteId = MarshallUtil.unmarshallString(input); + this.nodeId = MarshallUtil.unmarshallString(input); + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/AuthenticationSessionPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/AuthenticationSessionPredicate.java index 32bf3a6939..30747daea8 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/AuthenticationSessionPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/AuthenticationSessionPredicate.java @@ -17,18 +17,25 @@ package org.keycloak.models.sessions.infinispan.stream; -import java.io.Serializable; import java.util.Map; import java.util.function.Predicate; import org.keycloak.models.sessions.infinispan.entities.AuthenticationSessionEntity; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Marek Posolda */ -public class AuthenticationSessionPredicate implements Predicate>, Serializable { +@SerializeWith(AuthenticationSessionPredicate.ExternalizerImpl.class) +public class AuthenticationSessionPredicate implements Predicate> { - private String realm; + private final String realm; private String client; @@ -102,4 +109,38 @@ public class AuthenticationSessionPredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, AuthenticationSessionPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realm, output); + MarshallUtil.marshallString(obj.user, output); + MarshallUtil.marshallString(obj.client, output); + KeycloakMarshallUtil.marshall(obj.expired, output); + + } + + @Override + public AuthenticationSessionPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public AuthenticationSessionPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + AuthenticationSessionPredicate res = new AuthenticationSessionPredicate(MarshallUtil.unmarshallString(input)); + res.user(MarshallUtil.unmarshallString(input)); + res.client(MarshallUtil.unmarshallString(input)); + res.expired(KeycloakMarshallUtil.unmarshallInteger(input)); + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/SessionPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/SessionPredicate.java index 1820cda77e..b93afcd41f 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/SessionPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/SessionPredicate.java @@ -20,16 +20,22 @@ package org.keycloak.models.sessions.infinispan.stream; import org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper; import org.keycloak.models.sessions.infinispan.entities.SessionEntity; -import java.io.Serializable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Stian Thorgersen */ -public class SessionPredicate implements Predicate>>, Serializable { +@SerializeWith(SessionPredicate.ExternalizerImpl.class) +public class SessionPredicate implements Predicate>> { - private String realm; + private final String realm; private SessionPredicate(String realm) { this.realm = realm; @@ -44,4 +50,31 @@ public class SessionPredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, SessionPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realm, output); + + } + + @Override + public SessionPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public SessionPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + SessionPredicate res = new SessionPredicate(MarshallUtil.unmarshallString(input)); + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserLoginFailurePredicate.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserLoginFailurePredicate.java index ef6155fbdb..4b7ca6beea 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserLoginFailurePredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserLoginFailurePredicate.java @@ -21,16 +21,22 @@ import org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper; import org.keycloak.models.sessions.infinispan.entities.LoginFailureEntity; import org.keycloak.models.sessions.infinispan.entities.LoginFailureKey; -import java.io.Serializable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Stian Thorgersen */ -public class UserLoginFailurePredicate implements Predicate>>, Serializable { +@SerializeWith(UserLoginFailurePredicate.ExternalizerImpl.class) +public class UserLoginFailurePredicate implements Predicate>> { - private String realm; + private final String realm; private UserLoginFailurePredicate(String realm) { this.realm = realm; @@ -46,4 +52,31 @@ public class UserLoginFailurePredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserLoginFailurePredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realm, output); + + } + + @Override + public UserLoginFailurePredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserLoginFailurePredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserLoginFailurePredicate res = new UserLoginFailurePredicate(MarshallUtil.unmarshallString(input)); + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserSessionPredicate.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserSessionPredicate.java index 166ee4d6ce..d240b13bc5 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserSessionPredicate.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/stream/UserSessionPredicate.java @@ -21,16 +21,23 @@ import org.keycloak.models.sessions.infinispan.changes.SessionEntityWrapper; import org.keycloak.models.sessions.infinispan.entities.SessionEntity; import org.keycloak.models.sessions.infinispan.entities.UserSessionEntity; -import java.io.Serializable; +import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Map; import java.util.function.Predicate; +import org.infinispan.commons.marshall.Externalizer; +import org.infinispan.commons.marshall.MarshallUtil; +import org.infinispan.commons.marshall.SerializeWith; /** * @author Stian Thorgersen */ -public class UserSessionPredicate implements Predicate>>, Serializable { +@SerializeWith(UserSessionPredicate.ExternalizerImpl.class) +public class UserSessionPredicate implements Predicate>> { - private String realm; + private final String realm; private String user; @@ -113,4 +120,43 @@ public class UserSessionPredicate implements Predicate { + + private static final int VERSION_1 = 1; + + @Override + public void writeObject(ObjectOutput output, UserSessionPredicate obj) throws IOException { + output.writeByte(VERSION_1); + + MarshallUtil.marshallString(obj.realm, output); + MarshallUtil.marshallString(obj.user, output); + MarshallUtil.marshallString(obj.client, output); + KeycloakMarshallUtil.marshall(obj.expired, output); + KeycloakMarshallUtil.marshall(obj.expiredRefresh, output); + MarshallUtil.marshallString(obj.brokerSessionId, output); + MarshallUtil.marshallString(obj.brokerUserId, output); + + } + + @Override + public UserSessionPredicate readObject(ObjectInput input) throws IOException, ClassNotFoundException { + switch (input.readByte()) { + case VERSION_1: + return readObjectVersion1(input); + default: + throw new IOException("Unknown version"); + } + } + + public UserSessionPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { + UserSessionPredicate res = new UserSessionPredicate(MarshallUtil.unmarshallString(input)); + res.user(MarshallUtil.unmarshallString(input)); + res.client(MarshallUtil.unmarshallString(input)); + res.expired(KeycloakMarshallUtil.unmarshallInteger(input), KeycloakMarshallUtil.unmarshallInteger(input)); + res.brokerSessionId(MarshallUtil.unmarshallString(input)); + res.brokerUserId(MarshallUtil.unmarshallString(input)); + return res; + } + } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java index e732c11ccb..df5c8c673a 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/util/KeycloakMarshallUtil.java @@ -126,7 +126,31 @@ public class KeycloakMarshallUtil { } } + /** + * Marshalls the given object with support of {@code null} values. + * @param obj Object to marshall (can be {@code null}) + * @param output Output stream + * @throws IOException + */ + public static void marshall(Integer obj, ObjectOutput output) throws IOException { + if (obj == null) { + output.writeBoolean(false); + } else { + output.writeBoolean(true); + output.writeInt(obj); + } + } + /** + * Unmarshals the given object into {@code Integer} instance. + * @param input Input stream + * @return Unmarshalled value (can be {@code null}) + * @throws IOException + */ + public static Integer unmarshallInteger(ObjectInput input) throws IOException { + boolean isSet = input.readBoolean(); + return isSet ? input.readInt() : null; + } public static class ConcurrentHashMapBuilder implements MarshallUtil.MapBuilder> {