-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/Microsoft.IdentityModel.Tokens/Validation/SigningKeyValidationResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
#nullable enable | ||
namespace Microsoft.IdentityModel.Tokens | ||
{ | ||
/// <summary> | ||
/// Contains the result of validating the <see cref="SecurityKey"/> used to sign a <see cref="SecurityToken"/>. | ||
/// The <see cref="TokenValidationResult"/> contains a collection of <see cref="ValidationResult"/> for each step in the token validation. | ||
/// </summary> | ||
internal class SigningKeyValidationResult : ValidationResult | ||
{ | ||
private Exception? _exception; | ||
|
||
/// <summary> | ||
/// Creates an instance of <see cref="SigningKeyValidationResult"/> | ||
/// </summary> | ||
/// <paramref name="signingKey"/> is the security key that was validated successfully. | ||
public SigningKeyValidationResult(SecurityKey? signingKey) | ||
: base(ValidationFailureType.ValidationSucceeded) | ||
{ | ||
SigningKey = signingKey; | ||
IsValid = true; | ||
} | ||
|
||
/// <summary> | ||
/// Creates an instance of <see cref="SigningKeyValidationResult"/> | ||
/// </summary> | ||
/// <paramref name="signingKey"/> is the security key that was intended to be validated. | ||
/// <paramref name="validationFailure"/> is the <see cref="ValidationFailureType"/> that occurred during validation. | ||
/// <paramref name="exceptionDetail"/> is the <see cref="ExceptionDetail"/> that occurred during validation. | ||
public SigningKeyValidationResult(SecurityKey? signingKey, ValidationFailureType validationFailure, ExceptionDetail exceptionDetail) | ||
: base(validationFailure, exceptionDetail) | ||
{ | ||
SigningKey = signingKey; | ||
IsValid = false; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="Exception"/> that occurred during validation. | ||
/// </summary> | ||
public override Exception? Exception | ||
{ | ||
get | ||
{ | ||
if (_exception != null || ExceptionDetail == null) | ||
return _exception; | ||
|
||
HasValidOrExceptionWasRead = true; | ||
_exception = ExceptionDetail.GetException(); | ||
if (_exception is SecurityTokenInvalidSigningKeyException securityTokenInvalidSigningKeyException) | ||
{ | ||
securityTokenInvalidSigningKeyException.SigningKey = SigningKey; | ||
securityTokenInvalidSigningKeyException.ExceptionDetail = ExceptionDetail; | ||
securityTokenInvalidSigningKeyException.Source = "Microsoft.IdentityModel.Tokens"; | ||
} | ||
|
||
return _exception; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the security key that was validated or intended to be validated. | ||
/// </summary> | ||
public SecurityKey? SigningKey { get; } | ||
} | ||
} | ||
#nullable restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters