Allow null Protostream fields

Closes #30761

Co-authored-by: Pedro Ruivo <pruivo@redhat.com>
Signed-off-by: Ryan Emerson <remerson@redhat.com>
This commit is contained in:
Ryan Emerson 2024-07-03 09:03:58 +01:00 committed by Alexander Schwartz
parent bbe05e729f
commit bf26d3364c
16 changed files with 40 additions and 40 deletions

View file

@ -66,21 +66,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-types</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<!-- compile-only dependency -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -98,7 +83,7 @@
<build>
<plugins>
<plugin>
<groupId>org.infinispan.maven-plugins</groupId>
<groupId>org.infinispan.protostream</groupId>
<artifactId>proto-schema-compatibility-maven-plugin</artifactId>
<executions>
<execution>

View file

@ -57,7 +57,7 @@ public class WrapperClusterEvent implements ClusterEvent {
@ProtoFactory
static WrapperClusterEvent protoFactory(String eventKey, String senderAddress, String senderSite, SiteFilter siteFilter, List<WrappedMessage> 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<? extends ClusterEvent> events, String senderAddress, String senderSite, ClusterProvider.DCNotify dcNotify, boolean ignoreSender) {

View file

@ -94,6 +94,7 @@ import org.keycloak.storage.managers.UserStorageSyncManager;
syntax = ProtoSyntax.PROTO3,
schemaPackageName = "keycloak",
schemaFilePath = "proto/generated",
allowNullFields = true,
// common-types for UUID
dependsOn = CommonTypes.class,

View file

@ -155,9 +155,4 @@ public final class Marshalling {
public static void configure(ConfigurationBuilder builder) {
builder.addContextInitializer(KeycloakModelSchema.INSTANCE);
}
public static String emptyStringToNull(String value) {
return value == null || value.isEmpty() ? null : value;
}
}

View file

@ -32,7 +32,7 @@ public class ResourceRemovedEvent extends BaseResourceEvent {
@ProtoFactory
static ResourceRemovedEvent protoFactory(String id, String name, String owner, String serverId, String type, Set<String> uris, Set<String> 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<String> uris, Set<String> scopes) {

View file

@ -32,7 +32,7 @@ public class ResourceUpdatedEvent extends BaseResourceEvent {
@ProtoFactory
static ResourceUpdatedEvent protoFactory(String id, String name, String owner, String serverId, String type, Set<String> uris, Set<String> 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<String> uris, Set<String> scopes) {

View file

@ -46,7 +46,7 @@ public class GroupAddedEvent extends InvalidationEvent implements RealmCacheInva
@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) {

View file

@ -49,7 +49,7 @@ public class GroupMovedEvent extends InvalidationEvent implements RealmCacheInva
@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) {

View file

@ -46,7 +46,7 @@ public class GroupRemovedEvent extends InvalidationEvent implements RealmCacheIn
@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) {

View file

@ -53,7 +53,7 @@ public class UserFederationLinkRemovedEvent extends InvalidationEvent implements
@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)

View file

@ -70,7 +70,7 @@ public class UserFullInvalidationEvent extends InvalidationEvent implements User
@ProtoFactory
static UserFullInvalidationEvent protoFactory(String id, String username, String email, String realmId, boolean identityFederationEnabled, Map<String, String> federatedIdentities) {
return new UserFullInvalidationEvent(id, username, Marshalling.emptyStringToNull(email), realmId, identityFederationEnabled, federatedIdentities);
return new UserFullInvalidationEvent(id, username, email, realmId, identityFederationEnabled, federatedIdentities);
}
public Map<String, String> getFederatedIdentities() {

View file

@ -52,7 +52,7 @@ public class UserUpdatedEvent extends InvalidationEvent implements UserCacheInva
@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

View file

@ -156,9 +156,9 @@ public class AuthenticatedClientSessionEntity extends SessionEntity {
AuthenticatedClientSessionEntity(String realmId, String authMethod, String redirectUri, int timestamp, String action, Map<String, String> 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;
}

View file

@ -51,7 +51,7 @@ public class LoginFailureEntity extends SessionEntity {
this.numFailures = numFailures;
this.numTemporaryLockouts = numTemporaryLockouts;
this.lastFailure = lastFailure;
this.lastIPFailure = Marshalling.emptyStringToNull(lastIPFailure);
this.lastIPFailure = lastIPFailure;
}
@ProtoField(2)

View file

@ -118,10 +118,10 @@ public class UserSessionPredicate implements Predicate<Map.Entry<String, Session
@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

25
pom.xml
View file

@ -100,6 +100,7 @@
<hibernate-orm.plugin.version>6.2.13.Final</hibernate-orm.plugin.version>
<hibernate.c3p0.version>6.2.13.Final</hibernate.c3p0.version>
<infinispan.version>15.0.5.Final</infinispan.version>
<protostream.version>5.0.7.Final</protostream.version>
<!--JAKARTA-->
<jakarta.mail.version>2.1.1</jakarta.mail.version>
@ -199,7 +200,6 @@
<smallrye.openapi.generator.plugin.version>3.6.2</smallrye.openapi.generator.plugin.version>
<openapi.generator.plugin.version>6.3.0</openapi.generator.plugin.version>
<build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
<infinispan.maven-plugins.version>1.0.5.Final</infinispan.maven-plugins.version>
<!-- Surefire Settings -->
<surefire.memory.Xms>512m</surefire.memory.Xms>
@ -1439,6 +1439,25 @@
<artifactId>rdf-urdna</artifactId>
<version>${io.setl.rdf-urdna.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream</artifactId>
<version>${protostream.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-types</artifactId>
<version>${protostream.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<version>${protostream.version}</version>
<!-- compile-only dependency -->
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
@ -1695,9 +1714,9 @@
<version>${build-helper-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.infinispan.maven-plugins</groupId>
<groupId>org.infinispan.protostream</groupId>
<artifactId>proto-schema-compatibility-maven-plugin</artifactId>
<version>${infinispan.maven-plugins.version}</version>
<version>${protostream.version}</version>
<configuration>
<commitProtoLock>${commitProtoLockChanges}</commitProtoLock>
</configuration>