| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | using Elsa.ExternalAuthentication.Options; |
| | | 4 | | using Elsa.ExternalAuthentication.Policies; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.ExternalAuthentication.Validation; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Validates the deployment-owned External Authentication configuration before it is used by the broker. |
| | | 12 | | /// </summary> |
| | 34 | 13 | | public sealed class ExternalAuthenticationOptionsValidator( |
| | 34 | 14 | | IOptions<ExternalAuthenticationExtensionOptions> extensionOptions, |
| | 34 | 15 | | ILogger<ExternalAuthenticationOptionsValidator> logger) : IValidateOptions<ExternalAuthenticationOptions> |
| | | 16 | | { |
| | | 17 | | public ValidateOptionsResult Validate(string? name, ExternalAuthenticationOptions options) |
| | | 18 | | { |
| | 33 | 19 | | var failures = new List<string>(); |
| | 33 | 20 | | var registrations = extensionOptions.Value.Registrations; |
| | 284 | 21 | | var installedAdapterTypes = ValidateExtensionTypes(registrations.Where(x => x.Kind == ExternalAuthenticationExte |
| | 313 | 22 | | var installedPolicyTypes = ValidateExtensionTypes(registrations.Where(x => x.Kind == ExternalAuthenticationExten |
| | 370 | 23 | | var installedGrantSourceTypes = ValidateExtensionTypes(registrations.Where(x => x.Kind == ExternalAuthentication |
| | 250 | 24 | | var installedMatcherTypes = ValidateExtensionTypes(registrations.Where(x => x.Kind == ExternalAuthenticationExte |
| | | 25 | | |
| | 33 | 26 | | ValidateAllowedTypes(options.AllowedAdapterTypes, installedAdapterTypes, "adapter", failures); |
| | 33 | 27 | | ValidateAllowedTypes(options.AllowedUnlinkedIdentityPolicyTypes, installedPolicyTypes, "unlinked identity policy |
| | 33 | 28 | | ValidateAllowedTypes(options.AllowedPermissionGrantSourceTypes, installedGrantSourceTypes, "permission grant sou |
| | 33 | 29 | | ValidateAllowedTypes(options.AllowedExternalUserMatcherTypes, installedMatcherTypes, "external user matcher", fa |
| | 33 | 30 | | if (string.Equals(options.UnlinkedIdentityPolicy.DefaultType, MatchExternalUserUnlinkedIdentityPolicy.PolicyType |
| | 33 | 31 | | (installedMatcherTypes.Count == 0 || options.AllowedExternalUserMatcherTypes.Count > 0 && !installedMatcherT |
| | 0 | 32 | | failures.Add("The default unlinked identity policy 'match-user' requires at least one installed and allowed |
| | 33 | 33 | | ValidateExternalCallbackBaseUri(options.Redirects, failures); |
| | 33 | 34 | | ValidateClients(options, failures); |
| | 33 | 35 | | ValidateConfigurationConnections(options, installedAdapterTypes, installedPolicyTypes, installedGrantSourceTypes |
| | 33 | 36 | | ValidateRateLimits(options.RateLimits, failures); |
| | 33 | 37 | | ValidateProviderEgress(options.ProviderEgress, failures); |
| | 33 | 38 | | ValidateHandleHashing(options.HandleHashing, failures); |
| | 33 | 39 | | ValidatePermissionGrantBoundary(options.PermissionGrants, failures); |
| | | 40 | | |
| | 33 | 41 | | return failures.Count == 0 ? ValidateOptionsResult.Success : ValidateOptionsResult.Fail(failures); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Rejects a grant boundary that cannot be parsed. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <remarks> |
| | | 48 | | /// The boundary is security configuration, so a malformed entry has no safe silent reading: an unparseable |
| | | 49 | | /// allow entry would leave the list empty, which means unrestricted, and an unparseable deny entry would |
| | | 50 | | /// quietly stop denying what it names. Failing startup puts the mistake in front of whoever can fix it |
| | | 51 | | /// instead of leaving it to be discovered from an issued token. |
| | | 52 | | /// </remarks> |
| | | 53 | | private void ValidatePermissionGrantBoundary(PermissionGrantOptions? permissionGrants, ICollection<string> failures) |
| | | 54 | | { |
| | 33 | 55 | | if (permissionGrants is null) |
| | 0 | 56 | | return; |
| | | 57 | | |
| | 33 | 58 | | ValidatePermissionPatterns(permissionGrants.AllowedPermissions, "AllowedPermissions", failures); |
| | 33 | 59 | | ValidatePermissionPatterns(permissionGrants.DeniedPermissions, "DeniedPermissions", failures); |
| | | 60 | | |
| | | 61 | | // Deny entries match in both directions, so a wildcard grant that could reach a denied permission is |
| | | 62 | | // refused whole rather than narrowed — a role holding '*' does not survive external token issuance. |
| | | 63 | | // That is intended, but surprising enough at sign-in time to be worth announcing at startup. |
| | 33 | 64 | | if (permissionGrants.DeniedPermissions is { Count: > 0 }) |
| | 9 | 65 | | logger.LogWarning( |
| | 9 | 66 | | "ExternalAuthentication:PermissionGrants:DeniedPermissions is configured. Deny entries match wildcard gr |
| | 33 | 67 | | } |
| | | 68 | | |
| | | 69 | | private static void ValidatePermissionPatterns(IEnumerable<string>? permissions, string listName, ICollection<string |
| | | 70 | | { |
| | 170 | 71 | | foreach (var permission in permissions ?? []) |
| | | 72 | | { |
| | 19 | 73 | | if (!Permission.TryParse(permission, out var parsed)) |
| | 6 | 74 | | failures.Add($"'{permission}' in ExternalAuthentication:PermissionGrants:{listName} is not a well-formed |
| | | 75 | | // An entry like 'workflows*:delete' parses but the matcher never satisfies it, so in a deny |
| | | 76 | | // list it would silently stop denying what it names. |
| | 13 | 77 | | else if (!parsed.IsValidPattern) |
| | 8 | 78 | | failures.Add($"'{permission}' in ExternalAuthentication:PermissionGrants:{listName} places '*' where it |
| | | 79 | | } |
| | 66 | 80 | | } |
| | | 81 | | |
| | | 82 | | private static void ValidateExternalCallbackBaseUri(RedirectValidationOptions? redirects, ICollection<string> failur |
| | | 83 | | { |
| | 33 | 84 | | if (redirects?.ExternalCallbackBaseUri is null) |
| | 30 | 85 | | return; |
| | | 86 | | |
| | 3 | 87 | | if (!ExternalCallbackBaseUriValidator.IsValid(redirects.ExternalCallbackBaseUri, redirects.AllowDevelopmentLoopb |
| | 2 | 88 | | failures.Add(ExternalCallbackBaseUriValidator.ErrorMessage); |
| | 3 | 89 | | } |
| | | 90 | | |
| | | 91 | | private static void ValidateHandleHashing(ExternalAuthenticationHandleHashingOptions? handleHashing, ICollection<str |
| | | 92 | | { |
| | 33 | 93 | | if (handleHashing is null) |
| | | 94 | | { |
| | 0 | 95 | | failures.Add("External Authentication handle-hashing settings are required."); |
| | 0 | 96 | | return; |
| | | 97 | | } |
| | | 98 | | |
| | 33 | 99 | | if (string.IsNullOrWhiteSpace(handleHashing.SharedKeyBase64)) |
| | 31 | 100 | | return; |
| | | 101 | | |
| | 2 | 102 | | byte[]? key = null; |
| | | 103 | | try |
| | | 104 | | { |
| | 2 | 105 | | key = Convert.FromBase64String(handleHashing.SharedKeyBase64); |
| | 1 | 106 | | if (key.Length < 32) |
| | 1 | 107 | | failures.Add("External Authentication HandleHashing:SharedKeyBase64 must contain at least 32 bytes."); |
| | 1 | 108 | | } |
| | 1 | 109 | | catch (FormatException) |
| | | 110 | | { |
| | 1 | 111 | | failures.Add("External Authentication HandleHashing:SharedKeyBase64 must be valid base64."); |
| | 1 | 112 | | } |
| | | 113 | | finally |
| | | 114 | | { |
| | 2 | 115 | | if (key is not null) |
| | 1 | 116 | | System.Security.Cryptography.CryptographicOperations.ZeroMemory(key); |
| | 2 | 117 | | } |
| | 2 | 118 | | } |
| | | 119 | | |
| | | 120 | | private static void ValidateRateLimits(ExternalAuthenticationRateLimitOptions rateLimits, ICollection<string> failur |
| | | 121 | | { |
| | 396 | 122 | | foreach (var (name, rule) in new (string Name, RateLimitRule? Rule)[] |
| | 33 | 123 | | { |
| | 33 | 124 | | (nameof(rateLimits.Discovery), rateLimits.Discovery), |
| | 33 | 125 | | (nameof(rateLimits.ExternalInitiation), rateLimits.ExternalInitiation), |
| | 33 | 126 | | (nameof(rateLimits.LocalInitiation), rateLimits.LocalInitiation), |
| | 33 | 127 | | (nameof(rateLimits.ProviderCallback), rateLimits.ProviderCallback), |
| | 33 | 128 | | (nameof(rateLimits.TokenExchange), rateLimits.TokenExchange) |
| | 33 | 129 | | }) |
| | | 130 | | { |
| | 165 | 131 | | if (rule is null || rule.PermitLimit <= 0 || rule.Window <= TimeSpan.Zero) |
| | 1 | 132 | | failures.Add($"External Authentication rate limit '{name}' must have a positive permit limit and window. |
| | | 133 | | } |
| | 33 | 134 | | } |
| | | 135 | | |
| | | 136 | | private static void ValidateProviderEgress(ProviderEgressOptions? providerEgress, ICollection<string> failures) |
| | | 137 | | { |
| | 33 | 138 | | if (providerEgress is null) |
| | | 139 | | { |
| | 0 | 140 | | failures.Add("External Authentication provider egress settings are required."); |
| | 0 | 141 | | return; |
| | | 142 | | } |
| | | 143 | | |
| | 33 | 144 | | if (providerEgress.MaximumRedirects < 0) |
| | 1 | 145 | | failures.Add("External Authentication provider egress maximum redirects must not be negative."); |
| | 33 | 146 | | if (providerEgress.ConnectTimeout <= TimeSpan.Zero || providerEgress.RequestTimeout <= TimeSpan.Zero) |
| | 1 | 147 | | failures.Add("External Authentication provider egress timeouts must be positive."); |
| | 33 | 148 | | if (providerEgress.MaximumDiscoveryResponseBytes <= 0 || providerEgress.MaximumTokenResponseBytes <= 0 || provid |
| | 1 | 149 | | failures.Add("External Authentication provider egress response-size limits must be positive."); |
| | | 150 | | |
| | 68 | 151 | | foreach (var host in providerEgress.AllowedHosts ?? []) |
| | | 152 | | { |
| | 1 | 153 | | if (string.IsNullOrWhiteSpace(host) || host.Contains('*') || Uri.CheckHostName(host.TrimEnd('.')) == UriHost |
| | 1 | 154 | | failures.Add($"External Authentication provider egress allowed host '{host}' is invalid."); |
| | | 155 | | } |
| | | 156 | | |
| | 33 | 157 | | if (providerEgress.ProxyUri is { } proxyUri && |
| | 33 | 158 | | (!proxyUri.IsAbsoluteUri || |
| | 33 | 159 | | !string.Equals(proxyUri.Scheme, "http", StringComparison.OrdinalIgnoreCase) && !string.Equals(proxyUri.Sche |
| | 33 | 160 | | !string.IsNullOrEmpty(proxyUri.UserInfo) || |
| | 33 | 161 | | !string.IsNullOrEmpty(proxyUri.Fragment) || |
| | 33 | 162 | | proxyUri.HostNameType == UriHostNameType.Unknown)) |
| | 1 | 163 | | failures.Add("External Authentication provider egress proxy URI must be an absolute HTTP(S) URI without cred |
| | 33 | 164 | | } |
| | | 165 | | |
| | | 166 | | private static HashSet<string> ValidateExtensionTypes(IEnumerable<string> types, string kind, ICollection<string> fa |
| | | 167 | | { |
| | 132 | 168 | | var result = new HashSet<string>(StringComparer.Ordinal); |
| | | 169 | | |
| | 698 | 170 | | foreach (var type in types) |
| | | 171 | | { |
| | 217 | 172 | | if (string.IsNullOrWhiteSpace(type)) |
| | | 173 | | { |
| | 0 | 174 | | failures.Add($"Installed {kind} types must not be empty."); |
| | 0 | 175 | | continue; |
| | | 176 | | } |
| | | 177 | | |
| | 217 | 178 | | if (!result.Add(type)) |
| | 2 | 179 | | failures.Add($"The installed {kind} type '{type}' is registered more than once."); |
| | | 180 | | } |
| | | 181 | | |
| | 132 | 182 | | return result; |
| | | 183 | | } |
| | | 184 | | |
| | | 185 | | private static void ValidateAllowedTypes(IEnumerable<string>? allowedTypes, IReadOnlySet<string> installedTypes, str |
| | | 186 | | { |
| | 132 | 187 | | var seen = new HashSet<string>(StringComparer.Ordinal); |
| | | 188 | | |
| | 630 | 189 | | foreach (var type in allowedTypes ?? []) |
| | | 190 | | { |
| | 183 | 191 | | if (string.IsNullOrWhiteSpace(type)) |
| | | 192 | | { |
| | 0 | 193 | | failures.Add($"Allowed {kind} types must not be empty."); |
| | 0 | 194 | | continue; |
| | | 195 | | } |
| | | 196 | | |
| | 183 | 197 | | if (!seen.Add(type)) |
| | 1 | 198 | | failures.Add($"The allowed {kind} type '{type}' is configured more than once."); |
| | | 199 | | |
| | 183 | 200 | | if (!installedTypes.Contains(type)) |
| | 1 | 201 | | failures.Add($"The allowed {kind} type '{type}' is not installed."); |
| | | 202 | | } |
| | 132 | 203 | | } |
| | | 204 | | |
| | | 205 | | private static void ValidateClients(ExternalAuthenticationOptions options, ICollection<string> failures) |
| | | 206 | | { |
| | 33 | 207 | | var clientIds = new HashSet<string>(StringComparer.Ordinal); |
| | | 208 | | |
| | 72 | 209 | | foreach (var client in options.Clients ?? []) |
| | | 210 | | { |
| | 3 | 211 | | if (string.IsNullOrWhiteSpace(client.ClientId)) |
| | 0 | 212 | | failures.Add("Authentication client identifiers must not be empty."); |
| | 3 | 213 | | else if (!clientIds.Add(client.ClientId)) |
| | 0 | 214 | | failures.Add($"The authentication client identifier '{client.ClientId}' is configured more than once."); |
| | | 215 | | |
| | 3 | 216 | | var callbackUris = client.CallbackUris ?? new HashSet<Uri>(); |
| | 3 | 217 | | var logoutCallbackUris = client.LogoutCallbackUris ?? new HashSet<Uri>(); |
| | 3 | 218 | | var allowedOrigins = client.AllowedOrigins ?? new HashSet<string>(); |
| | 3 | 219 | | var allowedReturnPathPrefixes = client.AllowedReturnPathPrefixes ?? new HashSet<string>(); |
| | | 220 | | |
| | 3 | 221 | | if (callbackUris.Count == 0) |
| | 0 | 222 | | failures.Add($"Authentication client '{client.ClientId}' must register at least one callback URI."); |
| | | 223 | | |
| | 3 | 224 | | ValidateUris(client.ClientId, callbackUris, "callback", options.Redirects.AllowDevelopmentLoopbackCallbacks, |
| | 3 | 225 | | ValidateUris(client.ClientId, logoutCallbackUris, "logout callback", options.Redirects.AllowDevelopmentLoopb |
| | 3 | 226 | | ValidateOrigins(client.ClientId, allowedOrigins, options.Redirects.AllowDevelopmentLoopbackCallbacks, failur |
| | 3 | 227 | | ValidateReturnPathPrefixes(client.ClientId, allowedReturnPathPrefixes, failures); |
| | | 228 | | |
| | 3 | 229 | | if (client.ClientType == AuthenticationClientType.Public) |
| | | 230 | | { |
| | 3 | 231 | | if (client.SecretBinding is not null) |
| | 2 | 232 | | failures.Add($"Public authentication client '{client.ClientId}' must not define a client secret bind |
| | | 233 | | |
| | 3 | 234 | | if (allowedOrigins.Count == 0) |
| | 0 | 235 | | failures.Add($"Public authentication client '{client.ClientId}' must register at least one allowed o |
| | | 236 | | |
| | 3 | 237 | | var originSet = allowedOrigins.ToHashSet(StringComparer.Ordinal); |
| | 12 | 238 | | foreach (var callbackUri in callbackUris) |
| | | 239 | | { |
| | 3 | 240 | | if (callbackUri.IsAbsoluteUri && !string.IsNullOrWhiteSpace(callbackUri.Host) && !originSet.Contains |
| | 2 | 241 | | failures.Add($"Public authentication client '{client.ClientId}' callback URI '{callbackUri}' doe |
| | | 242 | | } |
| | | 243 | | } |
| | 0 | 244 | | else if (client.SecretBinding is null) |
| | 0 | 245 | | failures.Add($"Confidential authentication client '{client.ClientId}' must define a client secret bindin |
| | | 246 | | } |
| | 33 | 247 | | } |
| | | 248 | | |
| | | 249 | | private static void ValidateUris(string clientId, IEnumerable<Uri> uris, string registrationKind, bool allowDevelopm |
| | | 250 | | { |
| | 6 | 251 | | var registeredUris = new HashSet<string>(StringComparer.Ordinal); |
| | | 252 | | |
| | 20 | 253 | | foreach (var uri in uris) |
| | | 254 | | { |
| | 4 | 255 | | if (!IsExactClientUri(uri, allowDevelopmentLoopback)) |
| | | 256 | | { |
| | 1 | 257 | | failures.Add($"Authentication client '{clientId}' has an invalid {registrationKind} URI '{uri}'. Registr |
| | 1 | 258 | | continue; |
| | | 259 | | } |
| | | 260 | | |
| | 3 | 261 | | if (!registeredUris.Add(uri.AbsoluteUri)) |
| | 0 | 262 | | failures.Add($"Authentication client '{clientId}' registers {registrationKind} URI '{uri}' more than onc |
| | | 263 | | } |
| | 6 | 264 | | } |
| | | 265 | | |
| | | 266 | | private static void ValidateOrigins(string clientId, IEnumerable<string> origins, bool allowDevelopmentLoopback, ICo |
| | | 267 | | { |
| | 3 | 268 | | var registeredOrigins = new HashSet<string>(StringComparer.Ordinal); |
| | | 269 | | |
| | 12 | 270 | | foreach (var origin in origins) |
| | | 271 | | { |
| | 3 | 272 | | if (!Uri.TryCreate(origin, UriKind.Absolute, out var uri) || |
| | 3 | 273 | | !IsExactClientUri(uri, allowDevelopmentLoopback) || |
| | 3 | 274 | | uri.AbsolutePath != "/" || |
| | 3 | 275 | | uri.Query.Length != 0) |
| | | 276 | | { |
| | 1 | 277 | | failures.Add($"Authentication client '{clientId}' has invalid allowed origin '{origin}'. Origins must be |
| | 1 | 278 | | continue; |
| | | 279 | | } |
| | | 280 | | |
| | 2 | 281 | | var normalizedOrigin = uri.GetLeftPart(UriPartial.Authority); |
| | 2 | 282 | | if (!string.Equals(origin, normalizedOrigin, StringComparison.Ordinal)) |
| | 1 | 283 | | failures.Add($"Authentication client '{clientId}' allowed origin '{origin}' must not contain a path, que |
| | | 284 | | |
| | 2 | 285 | | if (!registeredOrigins.Add(normalizedOrigin)) |
| | 0 | 286 | | failures.Add($"Authentication client '{clientId}' registers allowed origin '{origin}' more than once."); |
| | | 287 | | } |
| | 3 | 288 | | } |
| | | 289 | | |
| | | 290 | | private static void ValidateReturnPathPrefixes(string clientId, IReadOnlySet<string> prefixes, ICollection<string> f |
| | | 291 | | { |
| | 3 | 292 | | if (prefixes.Count == 0) |
| | | 293 | | { |
| | 1 | 294 | | failures.Add($"Authentication client '{clientId}' must register at least one allowed return-path prefix."); |
| | 1 | 295 | | return; |
| | | 296 | | } |
| | | 297 | | |
| | 2 | 298 | | var registeredPrefixes = new HashSet<string>(StringComparer.Ordinal); |
| | 8 | 299 | | foreach (var prefix in prefixes) |
| | | 300 | | { |
| | 2 | 301 | | if (!ClientReturnPathValidator.TryValidateForClient(prefix, new HashSet<string>(StringComparer.Ordinal) { pr |
| | | 302 | | { |
| | 0 | 303 | | failures.Add($"Authentication client '{clientId}' has invalid allowed return-path prefix '{prefix}'."); |
| | 0 | 304 | | continue; |
| | | 305 | | } |
| | | 306 | | |
| | 2 | 307 | | if (!registeredPrefixes.Add(prefix)) |
| | 0 | 308 | | failures.Add($"Authentication client '{clientId}' registers allowed return-path prefix '{prefix}' more t |
| | | 309 | | } |
| | 2 | 310 | | } |
| | | 311 | | |
| | | 312 | | private static bool IsExactClientUri(Uri uri, bool allowDevelopmentLoopback) |
| | | 313 | | { |
| | 6 | 314 | | if (!uri.IsAbsoluteUri || !string.IsNullOrEmpty(uri.Fragment) || !string.IsNullOrEmpty(uri.UserInfo) || uri.Host |
| | 0 | 315 | | return false; |
| | | 316 | | |
| | 6 | 317 | | return string.Equals(uri.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) || |
| | 6 | 318 | | allowDevelopmentLoopback && uri.IsLoopback && string.Equals(uri.Scheme, Uri.UriSchemeHttp, StringComparison. |
| | | 319 | | } |
| | | 320 | | |
| | | 321 | | private static void ValidateConfigurationConnections( |
| | | 322 | | ExternalAuthenticationOptions options, |
| | | 323 | | IReadOnlySet<string> installedAdapterTypes, |
| | | 324 | | IReadOnlySet<string> installedPolicyTypes, |
| | | 325 | | IReadOnlySet<string> installedGrantSourceTypes, |
| | | 326 | | ICollection<string> failures) |
| | | 327 | | { |
| | 33 | 328 | | var connectionKeys = new HashSet<string>(StringComparer.Ordinal); |
| | 33 | 329 | | var configuredConnectionIds = new HashSet<string>(StringComparer.Ordinal); |
| | 33 | 330 | | var hasPreferredConnection = false; |
| | | 331 | | |
| | 80 | 332 | | foreach (var connection in options.ConfigurationConnections ?? []) |
| | | 333 | | { |
| | 7 | 334 | | var tenantId = string.IsNullOrWhiteSpace(connection.TenantId) ? ConnectionScope.HostTenantId : connection.Te |
| | 7 | 335 | | if (tenantId != ConnectionScope.HostTenantId) |
| | 3 | 336 | | failures.Add($"Configuration connection '{connection.Key}' must use the host scope in this version."); |
| | 7 | 337 | | var key = connection.Key?.Trim().ToLowerInvariant() ?? string.Empty; |
| | | 338 | | |
| | 7 | 339 | | if (string.IsNullOrWhiteSpace(key)) |
| | 0 | 340 | | failures.Add("Configuration connection keys must not be empty."); |
| | 7 | 341 | | else if (!connectionKeys.Add(key)) |
| | 1 | 342 | | failures.Add($"Configuration connection key '{connection.Key}' is configured more than once."); |
| | | 343 | | |
| | 7 | 344 | | if (!string.IsNullOrWhiteSpace(connection.Id) && !configuredConnectionIds.Add(connection.Id)) |
| | 0 | 345 | | failures.Add($"Configuration connection ID '{connection.Id}' is configured more than once."); |
| | | 346 | | |
| | 7 | 347 | | if (connection.IsPreferred && hasPreferredConnection) |
| | 1 | 348 | | failures.Add("Configuration connections define more than one preferred sign-in method."); |
| | 7 | 349 | | hasPreferredConnection |= connection.IsPreferred; |
| | | 350 | | |
| | 7 | 351 | | if (string.IsNullOrWhiteSpace(connection.AdapterType) || !installedAdapterTypes.Contains(connection.AdapterT |
| | 1 | 352 | | failures.Add($"Configuration connection '{connection.Key}' selects adapter type '{connection.AdapterType |
| | 6 | 353 | | else if (options.AllowedAdapterTypes.Count > 0 && !options.AllowedAdapterTypes.Contains(connection.AdapterTy |
| | 0 | 354 | | failures.Add($"Configuration connection '{connection.Key}' selects adapter type '{connection.AdapterType |
| | | 355 | | |
| | 7 | 356 | | if (connection.AdapterSettingsVersion <= 0) |
| | 0 | 357 | | failures.Add($"Configuration connection '{connection.Key}' must use a positive adapter settings version. |
| | | 358 | | |
| | 7 | 359 | | if (string.IsNullOrWhiteSpace(connection.DisplayName)) |
| | 0 | 360 | | failures.Add($"Configuration connection '{connection.Key}' must define a display name."); |
| | | 361 | | |
| | 7 | 362 | | ValidatePolicy(connection, options, installedPolicyTypes, failures); |
| | 7 | 363 | | ValidateGrantSources(connection, options, installedGrantSourceTypes, failures); |
| | | 364 | | } |
| | | 365 | | |
| | 33 | 366 | | } |
| | | 367 | | |
| | | 368 | | private static void ValidatePolicy(IdentityProviderConnection connection, ExternalAuthenticationOptions options, IRe |
| | | 369 | | { |
| | 7 | 370 | | var policy = connection.UnlinkedPolicy; |
| | 7 | 371 | | if (policy is null) |
| | 7 | 372 | | return; |
| | | 373 | | |
| | 0 | 374 | | if (policy.SettingsVersion <= 0) |
| | 0 | 375 | | failures.Add($"Configuration connection '{connection.Key}' must use a positive unlinked identity policy sett |
| | | 376 | | |
| | 0 | 377 | | if (!installedPolicyTypes.Contains(policy.Type)) |
| | 0 | 378 | | failures.Add($"Configuration connection '{connection.Key}' selects unlinked identity policy '{policy.Type}', |
| | 0 | 379 | | else if (options.AllowedUnlinkedIdentityPolicyTypes.Count > 0 && !options.AllowedUnlinkedIdentityPolicyTypes.Con |
| | 0 | 380 | | failures.Add($"Configuration connection '{connection.Key}' selects unlinked identity policy '{policy.Type}', |
| | 0 | 381 | | } |
| | | 382 | | |
| | | 383 | | private static void ValidateGrantSources(IdentityProviderConnection connection, ExternalAuthenticationOptions option |
| | | 384 | | { |
| | 7 | 385 | | var orders = new HashSet<int>(); |
| | 14 | 386 | | foreach (var grantSource in connection.PermissionGrantSources ?? []) |
| | | 387 | | { |
| | 0 | 388 | | if (!orders.Add(grantSource.Order)) |
| | 0 | 389 | | failures.Add($"Configuration connection '{connection.Key}' configures more than one permission grant sou |
| | | 390 | | |
| | 0 | 391 | | if (grantSource.SettingsVersion <= 0) |
| | 0 | 392 | | failures.Add($"Configuration connection '{connection.Key}' must use a positive permission grant source s |
| | | 393 | | |
| | 0 | 394 | | if (!installedGrantSourceTypes.Contains(grantSource.Type)) |
| | 0 | 395 | | failures.Add($"Configuration connection '{connection.Key}' selects permission grant source '{grantSource |
| | 0 | 396 | | else if (options.AllowedPermissionGrantSourceTypes.Count > 0 && !options.AllowedPermissionGrantSourceTypes.C |
| | 0 | 397 | | failures.Add($"Configuration connection '{connection.Key}' selects permission grant source '{grantSource |
| | | 398 | | } |
| | 7 | 399 | | } |
| | | 400 | | } |