Skip to content

Commit

Permalink
Allow null Protostream fields
Browse files Browse the repository at this point in the history
Closes keycloak#30761

Co-authored-by: Pedro Ruivo <[email protected]>
Signed-off-by: Ryan Emerson <[email protected]>
  • Loading branch information
2 people authored and ahus1 committed Jul 4, 2024
1 parent bbe05e7 commit bf26d33
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 40 deletions.
17 changes: 1 addition & 16 deletions model/infinispan/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
syntax = ProtoSyntax.PROTO3,
schemaPackageName = "keycloak",
schemaFilePath = "proto/generated",
allowNullFields = true,

// common-types for UUID
dependsOn = CommonTypes.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public boolean equals(Object o) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>

Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit bf26d33

Please sign in to comment.