Browse Source

Introduce a custom exception type that allows flowing multiple validation errors

pull/678/head
Kévin Chalet 7 years ago
parent
commit
50375c212d
  1. 5
      src/OpenIddict.Abstractions/OpenIddictConstants.cs
  2. 75
      src/OpenIddict.Abstractions/OpenIddictException.cs
  3. 79
      src/OpenIddict.Abstractions/OpenIddictExceptions.cs
  4. 96
      src/OpenIddict.Core/Managers/OpenIddictApplicationManager.cs
  5. 23
      src/OpenIddict.Core/Managers/OpenIddictAuthorizationManager.cs
  6. 23
      src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
  7. 22
      src/OpenIddict.Core/Managers/OpenIddictTokenManager.cs
  8. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
  9. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  10. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
  11. 4
      src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
  12. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  13. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  14. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  15. 4
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
  16. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
  17. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
  18. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
  19. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs
  20. 8
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Helpers.cs

5
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";

75
src/OpenIddict.Abstractions/OpenIddictException.cs

@ -1,75 +0,0 @@
using System;
using System.Runtime.Serialization;
namespace OpenIddict.Abstractions
{
/// <summary>
/// Represents an OpenIddict exception.
/// </summary>
public class OpenIddictException : Exception
{
/// <summary>
/// Creates a new <see cref="OpenIddictException"/>.
/// </summary>
/// <param name="reason">The reason of the exception.</param>
/// <param name="message">The exception message.</param>
public OpenIddictException(string reason, string message)
: base(message)
{
Reason = reason;
}
/// <summary>
/// Creates a new <see cref="OpenIddictException"/>.
/// </summary>
/// <param name="reason">The reason of the exception.</param>
/// <param name="message">The exception message.</param>
/// <param name="innerException">The inner exception.</param>
public OpenIddictException(string reason, string message, Exception innerException)
: base(message, innerException)
{
Reason = reason;
}
/// <summary>
/// Creates a new <see cref="OpenIddictException"/>.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
protected OpenIddictException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Reason = info.GetString(nameof(Reason));
}
/// <summary>
/// Gets the reason that caused the exception to be thrown.
/// </summary>
public string Reason { get; }
/// <summary>
/// Serializes the members of this class.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
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);
}
}
}

79
src/OpenIddict.Abstractions/OpenIddictExceptions.cs

@ -0,0 +1,79 @@
using System;
using System.Collections.Immutable;
using System.ComponentModel.DataAnnotations;
namespace OpenIddict.Abstractions
{
/// <summary>
/// Exposes common exceptions thrown by OpenIddict.
/// </summary>
public static class OpenIddictExceptions
{
/// <summary>
/// Represents an OpenIddict concurrency exception.
/// </summary>
public class ConcurrencyException : Exception
{
/// <summary>
/// Creates a new <see cref="ConcurrencyException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
public ConcurrencyException(string message)
: this(message, exception: null)
{
}
/// <summary>
/// Creates a new <see cref="ConcurrencyException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="exception">The inner exception.</param>
public ConcurrencyException(string message, Exception exception)
: base(message, exception)
{
}
}
/// <summary>
/// Represents an OpenIddict validation exception.
/// </summary>
public class ValidationException : Exception
{
/// <summary>
/// Creates a new <see cref="ValidationException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
public ValidationException(string message)
: this(message, ImmutableArray.Create<ValidationResult>())
{
}
/// <summary>
/// Creates a new <see cref="ValidationException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="results">The validation results.</param>
public ValidationException(string message, ImmutableArray<ValidationResult> results)
: this(message, results, exception: null)
{
}
/// <summary>
/// Creates a new <see cref="ValidationException"/>.
/// </summary>
/// <param name="message">The exception message.</param>
/// <param name="results">The validation results.</param>
/// <param name="exception">The inner exception.</param>
public ValidationException(string message, ImmutableArray<ValidationResult> results, Exception exception)
: base(message, exception)
{
Results = results;
}
/// <summary>
/// Gets the validation results associated with this exception.
/// </summary>
public ImmutableArray<ValidationResult> Results { get; }
}
}
}

96
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 <see cref="ValueTask{TResult}"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client type of the application (by default, "public").
/// </returns>
public virtual async ValueTask<string> GetClientTypeAsync(
public virtual ValueTask<string> 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);
}
/// <summary>
@ -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();

23
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);

23
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);

22
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);

4
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);

4
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);

4
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);

4
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);

4
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);

4
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);

4
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);

4
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);

4
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());

4
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());

4
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());

4
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());

8
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);

Loading…
Cancel
Save