From bf26d3364c58ee884e1a3d551d4ba2d15ecd97db Mon Sep 17 00:00:00 2001 From: Ryan Emerson Date: Wed, 3 Jul 2024 09:03:58 +0100 Subject: [PATCH] Allow null Protostream fields Closes #30761 Co-authored-by: Pedro Ruivo Signed-off-by: Ryan Emerson --- model/infinispan/pom.xml | 17 +------------ .../infinispan/WrapperClusterEvent.java | 2 +- .../marshalling/KeycloakModelSchema.java | 1 + .../org/keycloak/marshalling/Marshalling.java | 5 ---- .../events/ResourceRemovedEvent.java | 2 +- .../events/ResourceUpdatedEvent.java | 2 +- .../infinispan/events/GroupAddedEvent.java | 2 +- .../infinispan/events/GroupMovedEvent.java | 2 +- .../infinispan/events/GroupRemovedEvent.java | 2 +- .../UserFederationLinkRemovedEvent.java | 2 +- .../events/UserFullInvalidationEvent.java | 2 +- .../infinispan/events/UserUpdatedEvent.java | 2 +- .../AuthenticatedClientSessionEntity.java | 4 +-- .../entities/LoginFailureEntity.java | 2 +- .../stream/UserSessionPredicate.java | 8 +++--- pom.xml | 25 ++++++++++++++++--- 16 files changed, 40 insertions(+), 40 deletions(-) diff --git a/model/infinispan/pom.xml b/model/infinispan/pom.xml index 5b5c51c65a75..008252e45c40 100755 --- a/model/infinispan/pom.xml +++ b/model/infinispan/pom.xml @@ -66,21 +66,6 @@ provided - - org.infinispan.protostream - protostream - - - org.infinispan.protostream - protostream-types - - - org.infinispan.protostream - protostream-processor - - provided - - junit junit @@ -98,7 +83,7 @@ - org.infinispan.maven-plugins + org.infinispan.protostream proto-schema-compatibility-maven-plugin 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 05dd0f6fd4a6..63370fe7c660 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 @@ -57,7 +57,7 @@ private WrapperClusterEvent(String eventKey, String senderAddress, String sender @ProtoFactory static WrapperClusterEvent protoFactory(String eventKey, String senderAddress, String senderSite, SiteFilter siteFilter, List eventPS) { var events = eventPS.stream().map(WrappedMessage::getValue).map(ClusterEvent.class::cast).toList(); - return new WrapperClusterEvent(eventKey, Marshalling.emptyStringToNull(senderAddress), Marshalling.emptyStringToNull(senderSite), siteFilter, events); + return new WrapperClusterEvent(eventKey, senderAddress, senderSite, siteFilter, events); } public static WrapperClusterEvent wrap(String eventKey, Collection events, String senderAddress, String senderSite, ClusterProvider.DCNotify dcNotify, boolean ignoreSender) { diff --git a/model/infinispan/src/main/java/org/keycloak/marshalling/KeycloakModelSchema.java b/model/infinispan/src/main/java/org/keycloak/marshalling/KeycloakModelSchema.java index b322610490ff..c463359e6d1f 100644 --- a/model/infinispan/src/main/java/org/keycloak/marshalling/KeycloakModelSchema.java +++ b/model/infinispan/src/main/java/org/keycloak/marshalling/KeycloakModelSchema.java @@ -94,6 +94,7 @@ syntax = ProtoSyntax.PROTO3, schemaPackageName = "keycloak", schemaFilePath = "proto/generated", + allowNullFields = true, // common-types for UUID dependsOn = CommonTypes.class, diff --git a/model/infinispan/src/main/java/org/keycloak/marshalling/Marshalling.java b/model/infinispan/src/main/java/org/keycloak/marshalling/Marshalling.java index 9980c4752856..5ca13fb3af64 100644 --- a/model/infinispan/src/main/java/org/keycloak/marshalling/Marshalling.java +++ b/model/infinispan/src/main/java/org/keycloak/marshalling/Marshalling.java @@ -155,9 +155,4 @@ public static void configure(GlobalConfigurationBuilder builder) { public static void configure(ConfigurationBuilder builder) { builder.addContextInitializer(KeycloakModelSchema.INSTANCE); } - - - public static String emptyStringToNull(String value) { - return value == null || value.isEmpty() ? null : value; - } } 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 61a4ab9ed1f9..6f88bcf6534f 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 @@ -32,7 +32,7 @@ public class ResourceRemovedEvent extends BaseResourceEvent { @ProtoFactory static ResourceRemovedEvent protoFactory(String id, String name, String owner, String serverId, String type, Set uris, Set scopes) { - return new ResourceRemovedEvent(id, name, owner, serverId, Marshalling.emptyStringToNull(type), uris, scopes); + return new ResourceRemovedEvent(id, name, owner, serverId, type, uris, scopes); } private ResourceRemovedEvent(String id, String name, String owner, String serverId, String type, Set uris, Set scopes) { 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 78e578641e69..be0c276a3fb5 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 @@ -32,7 +32,7 @@ public class ResourceUpdatedEvent extends BaseResourceEvent { @ProtoFactory static ResourceUpdatedEvent protoFactory(String id, String name, String owner, String serverId, String type, Set uris, Set scopes) { - return new ResourceUpdatedEvent(id, name, owner, serverId, Marshalling.emptyStringToNull(type), uris, scopes); + return new ResourceUpdatedEvent(id, name, owner, serverId, type, uris, scopes); } private ResourceUpdatedEvent(String id, String name, String owner, String serverId, String type, Set uris, Set scopes) { 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 79df2f671d3c..2eedcbcc12fd 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 @@ -46,7 +46,7 @@ private GroupAddedEvent(String groupId, String realmId, String parentId) { @ProtoFactory static GroupAddedEvent protoFactory(String id, String realmId, String parentId) { - return new GroupAddedEvent(id, realmId, Marshalling.emptyStringToNull(parentId)); + return new GroupAddedEvent(id, realmId, parentId); } public static GroupAddedEvent create(String groupId, String parentId, String realmId) { 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 6e2ee7df9ad0..adbaba06d9c3 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 @@ -49,7 +49,7 @@ private GroupMovedEvent(String groupId, String newParentId, String oldParentId, @ProtoFactory static GroupMovedEvent protoFactory(String id, String newParentId, String oldParentId, String realmId) { - return new GroupMovedEvent(id, Marshalling.emptyStringToNull(newParentId), Marshalling.emptyStringToNull(oldParentId), realmId); + return new GroupMovedEvent(id, newParentId, oldParentId, realmId); } public static GroupMovedEvent create(GroupModel group, GroupModel toParent, String realmId) { 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 9f914b8dc31c..1fc0b41d6d15 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 @@ -46,7 +46,7 @@ public GroupRemovedEvent(String groupId, String realmId, String parentId) { @ProtoFactory static GroupRemovedEvent protoFactory(String id, String realmId, String parentId) { - return new GroupRemovedEvent(id, realmId, Marshalling.emptyStringToNull(parentId)); + return new GroupRemovedEvent(id, realmId, parentId); } public static GroupRemovedEvent create(GroupModel group, String realmId) { 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 b8b7e42bb05b..993b6af3fbc9 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 @@ -53,7 +53,7 @@ public static UserFederationLinkRemovedEvent create(String userId, String realmI @ProtoFactory static UserFederationLinkRemovedEvent protoFactory(String id, String realmId, String identityProviderId, String socialUserId) { - return new UserFederationLinkRemovedEvent(id, realmId, Marshalling.emptyStringToNull(identityProviderId), Marshalling.emptyStringToNull(socialUserId)); + return new UserFederationLinkRemovedEvent(id, realmId, identityProviderId, socialUserId); } @ProtoField(2) 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 7babc97eee75..34769a8b2ca9 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 @@ -70,7 +70,7 @@ public static UserFullInvalidationEvent create(String userId, String username, S @ProtoFactory static UserFullInvalidationEvent protoFactory(String id, String username, String email, String realmId, boolean identityFederationEnabled, Map federatedIdentities) { - return new UserFullInvalidationEvent(id, username, Marshalling.emptyStringToNull(email), realmId, identityFederationEnabled, federatedIdentities); + return new UserFullInvalidationEvent(id, username, email, realmId, identityFederationEnabled, federatedIdentities); } public Map getFederatedIdentities() { 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 9626e1320942..41bb8b330b7d 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 @@ -52,7 +52,7 @@ public static UserUpdatedEvent create(String id, String username, String email, @ProtoFactory static UserUpdatedEvent protoFactory(String id, String username, String email, String realmId) { - return new UserUpdatedEvent(id, username, Marshalling.emptyStringToNull(email), realmId); + return new UserUpdatedEvent(id, username, email, realmId); } @Override diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/AuthenticatedClientSessionEntity.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/AuthenticatedClientSessionEntity.java index dc7890c11084..ad61c0b34b73 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/AuthenticatedClientSessionEntity.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/AuthenticatedClientSessionEntity.java @@ -156,9 +156,9 @@ public boolean equals(Object o) { AuthenticatedClientSessionEntity(String realmId, String authMethod, String redirectUri, int timestamp, String action, Map notes, UUID id) { super(realmId); this.authMethod = authMethod; - this.redirectUri = Marshalling.emptyStringToNull(redirectUri); + this.redirectUri = redirectUri; this.timestamp = timestamp; - this.action = Marshalling.emptyStringToNull(action); + this.action = action; this.notes = notes; this.id = id; } diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/LoginFailureEntity.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/LoginFailureEntity.java index a76ca9c9bc89..d06010418111 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/LoginFailureEntity.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/entities/LoginFailureEntity.java @@ -51,7 +51,7 @@ public LoginFailureEntity(String realmId, String userId) { this.numFailures = numFailures; this.numTemporaryLockouts = numTemporaryLockouts; this.lastFailure = lastFailure; - this.lastIPFailure = Marshalling.emptyStringToNull(lastIPFailure); + this.lastIPFailure = lastIPFailure; } @ProtoField(2) 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 1e3d8dc88655..917b96e759d8 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 @@ -118,10 +118,10 @@ public String getClient() { @ProtoFactory static UserSessionPredicate create(String userId, String brokerSessionId, String brokerUserId, String realm, String client) { return create(realm) - .user(Marshalling.emptyStringToNull(userId)) - .client(Marshalling.emptyStringToNull(client)) - .brokerSessionId(Marshalling.emptyStringToNull(brokerSessionId)) - .brokerUserId(Marshalling.emptyStringToNull(brokerUserId)); + .user(userId) + .client(client) + .brokerSessionId(brokerSessionId) + .brokerUserId(brokerUserId); } @Override diff --git a/pom.xml b/pom.xml index d951d6d48482..078973c3c8a4 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,7 @@ 6.2.13.Final 6.2.13.Final 15.0.5.Final + 5.0.7.Final 2.1.1 @@ -199,7 +200,6 @@ 3.6.2 6.3.0 3.2.0 - 1.0.5.Final 512m @@ -1439,6 +1439,25 @@ rdf-urdna ${io.setl.rdf-urdna.version} + + + org.infinispan.protostream + protostream + ${protostream.version} + + + org.infinispan.protostream + protostream-types + ${protostream.version} + + + org.infinispan.protostream + protostream-processor + ${protostream.version} + + provided + + @@ -1695,9 +1714,9 @@ ${build-helper-maven-plugin.version} - org.infinispan.maven-plugins + org.infinispan.protostream proto-schema-compatibility-maven-plugin - ${infinispan.maven-plugins.version} + ${protostream.version} ${commitProtoLockChanges}