Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tenant config clone #124

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "4.0.0"
version = "4.0.1"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Object> items1 = List.of(array1);
List<Object> 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
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading