diff --git a/CHANGELOG.md b/CHANGELOG.md index cb2378be..a4014772 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [4.0.1] - 2023-10-19 + +- Fixes cloning of `TenantConfig` object to include `null` values + ## [4.0.0] - 2023-09-19 - Adds support for account linking diff --git a/build.gradle b/build.gradle index 62e73f81..0602b3b4 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' } -version = "4.0.0" +version = "4.0.1" repositories { mavenCentral() diff --git a/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java b/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java index db90e86a..15b2c109 100644 --- a/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java +++ b/src/main/java/io/supertokens/pluginInterface/multitenancy/TenantConfig.java @@ -61,7 +61,7 @@ public TenantConfig(TenantConfig other) { this.coreConfig = gson.fromJson(other.coreConfig.toString(), JsonObject.class); this.emailPasswordConfig = new EmailPasswordConfig(other.emailPasswordConfig.enabled); this.passwordlessConfig = new PasswordlessConfig(other.passwordlessConfig.enabled); - this.thirdPartyConfig = gson.fromJson(gson.toJsonTree(other.thirdPartyConfig).getAsJsonObject(), ThirdPartyConfig.class); + this.thirdPartyConfig = new ThirdPartyConfig(other.thirdPartyConfig.enabled, other.thirdPartyConfig.providers.clone()); } public boolean deepEquals(TenantConfig other) { diff --git a/src/main/java/io/supertokens/pluginInterface/multitenancy/ThirdPartyConfig.java b/src/main/java/io/supertokens/pluginInterface/multitenancy/ThirdPartyConfig.java index 456dc464..8e13d1d1 100644 --- a/src/main/java/io/supertokens/pluginInterface/multitenancy/ThirdPartyConfig.java +++ b/src/main/java/io/supertokens/pluginInterface/multitenancy/ThirdPartyConfig.java @@ -21,8 +21,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.Objects; +import java.util.*; public class ThirdPartyConfig { public final boolean enabled; @@ -35,6 +34,38 @@ public ThirdPartyConfig(boolean enabled, @Nullable Provider[] providers) { this.providers = providers == null ? new Provider[0] : providers; } + public static boolean unorderedArrayEquals(Object[] array1, Object[] array2) { + if (array1 == null && array2 == null) { + return true; + } else if (array1 == null || array2 == null) { + return false; + } + + List items1 = List.of(array1); + List items2 = new ArrayList<>(); + items2.addAll(Arrays.asList(array2)); + + if (items1.size() != items2.size()) return false; + + for (Object p1 : items1) { + boolean found = false; + for (Object p2 : items2) { + if (p1.equals(p2)) { + found = true; + break; + } + } + + if (!found) { + return false; + } else { + items2.remove(p1); + } + } + + return true; + } + public static class Provider { @Nonnull @@ -105,11 +136,15 @@ public Provider(@Nonnull String thirdPartyId, @Nonnull String name, @Nullable Pr @Override public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other instanceof Provider) { Provider otherProvider = (Provider) other; - return otherProvider.thirdPartyId.equals(this.thirdPartyId) && - otherProvider.name.equals(this.name) && - Arrays.equals(otherProvider.clients, this.clients) && + return Objects.equals(otherProvider.thirdPartyId, this.thirdPartyId) && + Objects.equals(otherProvider.name, this.name) && + unorderedArrayEquals(otherProvider.clients, this.clients) && Objects.equals(otherProvider.authorizationEndpoint, this.authorizationEndpoint) && Objects.equals(otherProvider.authorizationEndpointQueryParams, this.authorizationEndpointQueryParams) && @@ -165,7 +200,7 @@ public boolean equals(Object other) { return Objects.equals(otherProviderClient.clientType, this.clientType) && otherProviderClient.clientId.equals(this.clientId) && Objects.equals(otherProviderClient.clientSecret, this.clientSecret) && - Arrays.equals(otherProviderClient.scope, this.scope) && + unorderedArrayEquals(otherProviderClient.scope, this.scope) && otherProviderClient.forcePKCE == this.forcePKCE && Objects.equals(otherProviderClient.additionalConfig, this.additionalConfig); } @@ -230,7 +265,7 @@ public boolean equals(Object other) { if (other instanceof ThirdPartyConfig) { ThirdPartyConfig otherThirdPartyConfig = (ThirdPartyConfig) other; return otherThirdPartyConfig.enabled == this.enabled && - Arrays.equals(otherThirdPartyConfig.providers, this.providers); + unorderedArrayEquals(otherThirdPartyConfig.providers, this.providers); } return false; }