From 50375c212dfc894e5e10277abb0a1c959d769bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 2 Oct 2018 15:51:04 +0200 Subject: [PATCH] Introduce a custom exception type that allows flowing multiple validation errors --- .../OpenIddictConstants.cs | 5 - .../OpenIddictException.cs | 75 --------------- .../OpenIddictExceptions.cs | 79 +++++++++++++++ .../Managers/OpenIddictApplicationManager.cs | 96 +++++-------------- .../OpenIddictAuthorizationManager.cs | 23 ++++- .../Managers/OpenIddictScopeManager.cs | 23 ++++- .../Managers/OpenIddictTokenManager.cs | 22 ++++- .../Stores/OpenIddictApplicationStore.cs | 4 +- .../Stores/OpenIddictAuthorizationStore.cs | 4 +- .../Stores/OpenIddictScopeStore.cs | 4 +- .../Stores/OpenIddictTokenStore.cs | 4 +- .../Stores/OpenIddictApplicationStore.cs | 4 +- .../Stores/OpenIddictAuthorizationStore.cs | 4 +- .../Stores/OpenIddictScopeStore.cs | 4 +- .../Stores/OpenIddictTokenStore.cs | 4 +- .../Stores/OpenIddictApplicationStore.cs | 4 +- .../Stores/OpenIddictAuthorizationStore.cs | 4 +- .../Stores/OpenIddictScopeStore.cs | 4 +- .../Stores/OpenIddictTokenStore.cs | 4 +- .../OpenIddictServerProvider.Helpers.cs | 8 +- 20 files changed, 192 insertions(+), 187 deletions(-) delete mode 100644 src/OpenIddict.Abstractions/OpenIddictException.cs create mode 100644 src/OpenIddict.Abstractions/OpenIddictExceptions.cs diff --git a/src/OpenIddict.Abstractions/OpenIddictConstants.cs b/src/OpenIddict.Abstractions/OpenIddictConstants.cs index 3ca574d1..6337b175 100644 --- a/src/OpenIddict.Abstractions/OpenIddictConstants.cs +++ b/src/OpenIddict.Abstractions/OpenIddictConstants.cs @@ -118,11 +118,6 @@ namespace OpenIddict.Abstractions public const string UnsupportedTokenType = "unsupported_token_type"; } - public static class Exceptions - { - public const string ConcurrencyError = "concurrency_error"; - } - public static class GrantTypes { public const string AuthorizationCode = "authorization_code"; diff --git a/src/OpenIddict.Abstractions/OpenIddictException.cs b/src/OpenIddict.Abstractions/OpenIddictException.cs deleted file mode 100644 index 003bf397..00000000 --- a/src/OpenIddict.Abstractions/OpenIddictException.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace OpenIddict.Abstractions -{ - /// - /// Represents an OpenIddict exception. - /// - public class OpenIddictException : Exception - { - /// - /// Creates a new . - /// - /// The reason of the exception. - /// The exception message. - public OpenIddictException(string reason, string message) - : base(message) - { - Reason = reason; - } - - /// - /// Creates a new . - /// - /// The reason of the exception. - /// The exception message. - /// The inner exception. - public OpenIddictException(string reason, string message, Exception innerException) - : base(message, innerException) - { - Reason = reason; - } - - /// - /// Creates a new . - /// - /// - /// The that holds the serialized object data about the exception being thrown. - /// - /// - /// The that contains contextual information about the source or destination. - /// - protected OpenIddictException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - Reason = info.GetString(nameof(Reason)); - } - - /// - /// Gets the reason that caused the exception to be thrown. - /// - public string Reason { get; } - - /// - /// Serializes the members of this class. - /// - /// - /// The that holds the serialized object data about the exception being thrown. - /// - /// - /// The that contains contextual information about the source or destination. - /// - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - - info.AddValue(nameof(Reason), Reason); - - base.GetObjectData(info, context); - } - } -} diff --git a/src/OpenIddict.Abstractions/OpenIddictExceptions.cs b/src/OpenIddict.Abstractions/OpenIddictExceptions.cs new file mode 100644 index 00000000..b9d65650 --- /dev/null +++ b/src/OpenIddict.Abstractions/OpenIddictExceptions.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Immutable; +using System.ComponentModel.DataAnnotations; + +namespace OpenIddict.Abstractions +{ + /// + /// Exposes common exceptions thrown by OpenIddict. + /// + public static class OpenIddictExceptions + { + /// + /// Represents an OpenIddict concurrency exception. + /// + public class ConcurrencyException : Exception + { + /// + /// Creates a new . + /// + /// The exception message. + public ConcurrencyException(string message) + : this(message, exception: null) + { + } + + /// + /// Creates a new . + /// + /// The exception message. + /// The inner exception. + public ConcurrencyException(string message, Exception exception) + : base(message, exception) + { + } + } + + /// + /// Represents an OpenIddict validation exception. + /// + public class ValidationException : Exception + { + /// + /// Creates a new . + /// + /// The exception message. + public ValidationException(string message) + : this(message, ImmutableArray.Create()) + { + } + + /// + /// Creates a new . + /// + /// The exception message. + /// The validation results. + public ValidationException(string message, ImmutableArray results) + : this(message, results, exception: null) + { + } + + /// + /// Creates a new . + /// + /// The exception message. + /// The validation results. + /// The inner exception. + public ValidationException(string message, ImmutableArray results, Exception exception) + : base(message, exception) + { + Results = results; + } + + /// + /// Gets the validation results associated with this exception. + /// + public ImmutableArray Results { get; } + } + } +} diff --git a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs index 8fd2790d..8aaef7b1 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; using CryptoHelper; @@ -126,14 +127,6 @@ namespace OpenIddict.Core OpenIddictConstants.ClientTypes.Confidential, cancellationToken); } - // If the client is not a public application, throw an - // exception as the client secret is required in this case. - if (string.IsNullOrEmpty(secret) && !await IsPublicAsync(application, cancellationToken)) - { - throw new InvalidOperationException("A client secret must be provided when creating " + - "a confidential or hybrid application."); - } - // If a client secret was provided, obfuscate it. if (!string.IsNullOrEmpty(secret)) { @@ -144,7 +137,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(application, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, application); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to create a new application:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.CreateAsync(application, cancellationToken); @@ -418,7 +420,7 @@ namespace OpenIddict.Core /// A that can be used to monitor the asynchronous operation, /// whose result returns the client type of the application (by default, "public"). /// - public virtual async ValueTask GetClientTypeAsync( + public virtual ValueTask GetClientTypeAsync( [NotNull] TApplication application, CancellationToken cancellationToken = default) { if (application == null) @@ -426,18 +428,7 @@ namespace OpenIddict.Core throw new ArgumentNullException(nameof(application)); } - var type = await Store.GetClientTypeAsync(application, cancellationToken); - - // Ensure the application type returned by the store is supported by the manager. - if (!string.Equals(type, OpenIddictConstants.ClientTypes.Confidential, StringComparison.OrdinalIgnoreCase) && - !string.Equals(type, OpenIddictConstants.ClientTypes.Hybrid, StringComparison.OrdinalIgnoreCase) && - !string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) - { - throw new InvalidOperationException("Only 'confidential', 'hybrid' or 'public' applications are " + - "supported by the default application manager."); - } - - return type; + return Store.GetClientTypeAsync(application, cancellationToken); } /// @@ -829,7 +820,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(application, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, application); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to update an existing application:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.UpdateAsync(application, cancellationToken); @@ -1011,56 +1011,6 @@ namespace OpenIddict.Core } } - var permissions = await Store.GetPermissionsAsync(application, cancellationToken); - if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode)) - { - if (!permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Authorization) && - permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint))) - { - builder.Add(new ValidationResult( - "The authorization code flow permission requires adding the authorization endpoint permission.")); - } - - if (!permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) && - permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint))) - { - builder.Add(new ValidationResult( - "The authorization code flow permission requires adding the token endpoint permission.")); - } - } - - if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials) && - !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) && - permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint))) - { - builder.Add(new ValidationResult( - "The client credentials flow permission requires adding the token endpoint permission.")); - } - - if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.Implicit) && - !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Authorization) && - permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint))) - { - builder.Add(new ValidationResult( - "The implicit flow permission requires adding the authorization endpoint permission.")); - } - - if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.Password) && - !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) && - permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint))) - { - builder.Add(new ValidationResult( - "The password flow permission requires adding the token endpoint permission.")); - } - - if (permissions.Contains(OpenIddictConstants.Permissions.GrantTypes.RefreshToken) && - !permissions.Contains(OpenIddictConstants.Permissions.Endpoints.Token) && - permissions.Any(permission => permission.StartsWith(OpenIddictConstants.Permissions.Prefixes.Endpoint))) - { - builder.Add(new ValidationResult( - "The refresh token flow permission requires adding the token endpoint permission.")); - } - return builder.Count == builder.Capacity ? builder.MoveToImmutable() : builder.ToImmutable(); diff --git a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs index 772f4921..4c23cc53 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs @@ -9,6 +9,7 @@ using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Security.Claims; +using System.Text; using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; @@ -105,7 +106,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(authorization, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, authorization); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to create a new authorization:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.CreateAsync(authorization, cancellationToken); @@ -976,7 +986,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(authorization, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, authorization); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to update an existing authorization:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.UpdateAsync(authorization, cancellationToken); diff --git a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs index 38179591..0dc466ec 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; @@ -99,7 +100,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(scope, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, scope); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to create a new scope:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.CreateAsync(scope, cancellationToken); @@ -592,7 +602,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(scope, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, scope); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to update an existing scope:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.UpdateAsync(scope, cancellationToken); diff --git a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs index b8df734a..26aa034b 100644 --- a/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs +++ b/src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs @@ -106,7 +106,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(token, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, token); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to create a new token:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.CreateAsync(token, cancellationToken); @@ -1035,7 +1044,16 @@ namespace OpenIddict.Core var results = await ValidateAsync(token, cancellationToken); if (results.Any(result => result != ValidationResult.Success)) { - throw new ValidationException(results.FirstOrDefault(result => result != ValidationResult.Success), null, token); + var builder = new StringBuilder(); + builder.AppendLine("One or more validation error(s) occurred while trying to update an existing token:"); + builder.AppendLine(); + + foreach (var result in results) + { + builder.AppendLine(result.ErrorMessage); + } + + throw new OpenIddictExceptions.ValidationException(builder.ToString(), results); } await Store.UpdateAsync(token, cancellationToken); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs index a2cdacc5..a8942b8e 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs @@ -221,7 +221,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The application was concurrently updated and cannot be persisted in its current state.") .Append("Reload the application from the database and retry the operation.") .ToString(), exception); @@ -976,7 +976,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The application was concurrently updated and cannot be persisted in its current state.") .Append("Reload the application from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs index fc20a7cc..cb1e2244 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs @@ -203,7 +203,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.") .Append("Reload the authorization from the database and retry the operation.") .ToString(), exception); @@ -1000,7 +1000,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.") .Append("Reload the authorization from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs index 34bed152..59dc25bb 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs @@ -155,7 +155,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The scope was concurrently updated and cannot be persisted in its current state.") .Append("Reload the scope from the database and retry the operation.") .ToString(), exception); @@ -657,7 +657,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The scope was concurrently updated and cannot be persisted in its current state.") .Append("Reload the scope from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs index ba2f82bd..212e5a80 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs @@ -173,7 +173,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The token was concurrently updated and cannot be persisted in its current state.") .Append("Reload the token from the database and retry the operation.") .ToString(), exception); @@ -1176,7 +1176,7 @@ namespace OpenIddict.EntityFramework catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The token was concurrently updated and cannot be persisted in its current state.") .Append("Reload the token from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs index f290f577..216049fe 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs @@ -265,7 +265,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The application was concurrently updated and cannot be persisted in its current state.") .Append("Reload the application from the database and retry the operation.") .ToString(), exception); @@ -1043,7 +1043,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The application was concurrently updated and cannot be persisted in its current state.") .Append("Reload the application from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs index e0258e75..726f0ea3 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs @@ -241,7 +241,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.") .Append("Reload the authorization from the database and retry the operation.") .ToString(), exception); @@ -1112,7 +1112,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.") .Append("Reload the authorization from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs index 12a78c93..5777a949 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs @@ -173,7 +173,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The scope was concurrently updated and cannot be persisted in its current state.") .Append("Reload the scope from the database and retry the operation.") .ToString(), exception); @@ -698,7 +698,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The scope was concurrently updated and cannot be persisted in its current state.") .Append("Reload the scope from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs index a58dad06..a500346f 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs @@ -195,7 +195,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The token was concurrently updated and cannot be persisted in its current state.") .Append("Reload the token from the database and retry the operation.") .ToString(), exception); @@ -1301,7 +1301,7 @@ namespace OpenIddict.EntityFrameworkCore catch (DbUpdateConcurrencyException exception) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The token was concurrently updated and cannot be persisted in its current state.") .Append("Reload the token from the database and retry the operation.") .ToString(), exception); diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs index 8b0ba466..6d8c72ad 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs @@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb entity.Id == application.Id && entity.ConcurrencyToken == application.ConcurrencyToken)).DeletedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The application was concurrently updated and cannot be persisted in its current state.") .Append("Reload the application from the database and retry the operation.") .ToString()); @@ -819,7 +819,7 @@ namespace OpenIddict.MongoDb entity.Id == application.Id && entity.ConcurrencyToken == timestamp, application, null, cancellationToken)).MatchedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The application was concurrently updated and cannot be persisted in its current state.") .Append("Reload the application from the database and retry the operation.") .ToString()); diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs index 92e9117c..d35c75f2 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs @@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb entity.Id == authorization.Id && entity.ConcurrencyToken == authorization.ConcurrencyToken)).DeletedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.") .Append("Reload the authorization from the database and retry the operation.") .ToString()); @@ -883,7 +883,7 @@ namespace OpenIddict.MongoDb entity.Id == authorization.Id && entity.ConcurrencyToken == timestamp, authorization, null, cancellationToken)).MatchedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The authorization was concurrently updated and cannot be persisted in its current state.") .Append("Reload the authorization from the database and retry the operation.") .ToString()); diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs index 558c88de..cbee7399 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs @@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb entity.Id == scope.Id && entity.ConcurrencyToken == scope.ConcurrencyToken)).DeletedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The scope was concurrently updated and cannot be persisted in its current state.") .Append("Reload the scope from the database and retry the operation.") .ToString()); @@ -616,7 +616,7 @@ namespace OpenIddict.MongoDb entity.Id == scope.Id && entity.ConcurrencyToken == timestamp, scope, null, cancellationToken)).MatchedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The scope was concurrently updated and cannot be persisted in its current state.") .Append("Reload the scope from the database and retry the operation.") .ToString()); diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs index f602c80c..a7422ff9 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs @@ -137,7 +137,7 @@ namespace OpenIddict.MongoDb entity.Id == token.Id && entity.ConcurrencyToken == token.ConcurrencyToken)).DeletedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The token was concurrently updated and cannot be persisted in its current state.") .Append("Reload the token from the database and retry the operation.") .ToString()); @@ -997,7 +997,7 @@ namespace OpenIddict.MongoDb entity.Id == token.Id && entity.ConcurrencyToken == timestamp, token, null, cancellationToken)).MatchedCount == 0) { - throw new OpenIddictException(OpenIddictConstants.Exceptions.ConcurrencyError, new StringBuilder() + throw new OpenIddictExceptions.ConcurrencyException(new StringBuilder() .AppendLine("The token was concurrently updated and cannot be persisted in its current state.") .Append("Reload the token from the database and retry the operation.") .ToString()); diff --git a/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs b/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs index d9272489..4bfb1d34 100644 --- a/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs +++ b/src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs @@ -390,7 +390,7 @@ namespace OpenIddict.Server.Internal return true; } - catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError) + catch (OpenIddictExceptions.ConcurrencyException exception) { _logger.LogDebug(exception, "A concurrency exception occurred while trying to revoke the authorization " + "associated with the token '{Identifier}'.", identifier); @@ -423,7 +423,7 @@ namespace OpenIddict.Server.Internal return true; } - catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError) + catch (OpenIddictExceptions.ConcurrencyException exception) { _logger.LogDebug(exception, "A concurrency exception occurred while trying to revoke the token '{Identifier}'.", identifier); @@ -480,7 +480,7 @@ namespace OpenIddict.Server.Internal return true; } - catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError) + catch (OpenIddictExceptions.ConcurrencyException exception) { _logger.LogDebug(exception, "A concurrency exception occurred while trying to redeem with the token '{Identifier}'.", identifier); @@ -528,7 +528,7 @@ namespace OpenIddict.Server.Internal return true; } - catch (OpenIddictException exception) when (exception.Reason == OpenIddictConstants.Exceptions.ConcurrencyError) + catch (OpenIddictExceptions.ConcurrencyException exception) { _logger.LogDebug(exception, "A concurrency exception occurred while trying to update the " + "expiration date of the token '{Identifier}'.", identifier);