-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extensibility tests: Token Replay - JWT, SAML and SAML2 (#3032)
* Added TokenReplayValidationError and updated the default delegate to use it * Added log message, custom validation errors, custom delegates, and validation failure type for the token replay validation extensibility tests * Handle the potential case where the token replay delegate throws * Added extensibility tests for token replay * Resolved post merge unshipped API errors raised by Visual Studio
- Loading branch information
Showing
13 changed files
with
1,166 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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
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
54 changes: 54 additions & 0 deletions
54
src/Microsoft.IdentityModel.Tokens/Validation/Results/Details/TokenReplayValidationError.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,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
#nullable enable | ||
namespace Microsoft.IdentityModel.Tokens | ||
{ | ||
internal class TokenReplayValidationError : ValidationError | ||
{ | ||
internal TokenReplayValidationError( | ||
MessageDetail messageDetail, | ||
ValidationFailureType validationFailureType, | ||
Type exceptionType, | ||
StackFrame stackFrame, | ||
DateTime? expirationTime, | ||
Exception? innerException = null) | ||
: base(messageDetail, validationFailureType, exceptionType, stackFrame, innerException) | ||
{ | ||
ExpirationTime = expirationTime; | ||
} | ||
|
||
internal override Exception GetException() | ||
{ | ||
if (ExceptionType == typeof(SecurityTokenReplayDetectedException)) | ||
{ | ||
SecurityTokenReplayDetectedException exception = new(MessageDetail.Message, InnerException); | ||
exception.SetValidationError(this); | ||
|
||
return exception; | ||
} | ||
else if (ExceptionType == typeof(SecurityTokenReplayAddFailedException)) | ||
{ | ||
SecurityTokenReplayAddFailedException exception = new(MessageDetail.Message, InnerException); | ||
exception.SetValidationError(this); | ||
|
||
return exception; | ||
} | ||
|
||
return base.GetException(); | ||
} | ||
|
||
internal static new TokenReplayValidationError NullParameter(string parameterName, StackFrame stackFrame) => new( | ||
MessageDetail.NullParameter(parameterName), | ||
ValidationFailureType.NullArgument, | ||
typeof(SecurityTokenArgumentNullException), | ||
stackFrame, | ||
null); | ||
|
||
protected DateTime? ExpirationTime { 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
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
Oops, something went wrong.