| | | 1 | | using System.Text.Json; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.ExternalAuthentication.Services; |
| | | 5 | | |
| | | 6 | | internal static class IdentityProviderConnectionCloner |
| | | 7 | | { |
| | 263 | 8 | | public static IdentityProviderConnection Clone(IdentityProviderConnection source) => new() |
| | 263 | 9 | | { |
| | 263 | 10 | | Id = source.Id, |
| | 263 | 11 | | TenantId = source.TenantId, |
| | 263 | 12 | | Key = source.Key, |
| | 263 | 13 | | AdapterType = source.AdapterType, |
| | 263 | 14 | | AdapterSettingsVersion = source.AdapterSettingsVersion, |
| | 263 | 15 | | AdapterSettings = CloneJson(source.AdapterSettings), |
| | 263 | 16 | | SecretBindings = (source.SecretBindings ?? new Dictionary<string, SecretBinding>()) |
| | 64 | 17 | | .ToDictionary(x => x.Key, x => x.Value with { }, StringComparer.Ordinal), |
| | 263 | 18 | | DisplayName = source.DisplayName, |
| | 263 | 19 | | IconId = source.IconId, |
| | 263 | 20 | | DisplayOrder = source.DisplayOrder, |
| | 263 | 21 | | IsPreferred = source.IsPreferred, |
| | 263 | 22 | | IsEnabled = source.IsEnabled, |
| | 263 | 23 | | OverridesConfigurationConnection = source.OverridesConfigurationConnection, |
| | 263 | 24 | | ArchivedAt = source.ArchivedAt, |
| | 263 | 25 | | UnlinkedPolicy = source.UnlinkedPolicy is { } policy |
| | 263 | 26 | | ? new PolicySelection(policy.Type, policy.SettingsVersion, CloneJson(policy.Settings)) |
| | 263 | 27 | | : null, |
| | 263 | 28 | | PermissionGrantSources = (source.PermissionGrantSources ?? []) |
| | 0 | 29 | | .Select(x => new GrantSourceSelection(x.Type, x.SettingsVersion, CloneJson(x.Settings), x.Order)) |
| | 263 | 30 | | .ToArray(), |
| | 263 | 31 | | ClaimProjection = CloneProjection(source.ClaimProjection), |
| | 263 | 32 | | UpstreamLogoutMode = source.UpstreamLogoutMode, |
| | 263 | 33 | | Revision = source.Revision, |
| | 263 | 34 | | MaterialRevision = source.MaterialRevision, |
| | 263 | 35 | | CreatedAt = source.CreatedAt, |
| | 263 | 36 | | UpdatedAt = source.UpdatedAt |
| | 263 | 37 | | }; |
| | | 38 | | |
| | 308 | 39 | | public static JsonElement CloneJson(JsonElement value) => value.ValueKind == JsonValueKind.Undefined ? default : val |
| | | 40 | | |
| | | 41 | | private static ClaimProjection CloneProjection(ClaimProjection? source) |
| | | 42 | | { |
| | 263 | 43 | | source ??= ClaimProjection.Empty; |
| | 263 | 44 | | return new ClaimProjection( |
| | 263 | 45 | | new HashSet<string>(source.AllowedClaimTypes ?? new HashSet<string>(), StringComparer.Ordinal), |
| | 263 | 46 | | new HashSet<string>(source.RedactedClaimTypes ?? new HashSet<string>(), StringComparer.Ordinal), |
| | 263 | 47 | | source.MaximumClaimCount, |
| | 263 | 48 | | source.MaximumValueLength, |
| | 263 | 49 | | source.MaximumTotalBytes); |
| | | 50 | | } |
| | | 51 | | } |