-
Notifications
You must be signed in to change notification settings - Fork 435
Add cloud instance name validation #2804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cd41579
Added EnableAadSigningKeyValidation extension method to include cloud…
95e2333
Added tests to validate cloud instance validation
dca683d
Added tests to check that Issuer valdiation is still used
f47418e
SecurityTokenInvalidCloudInstanceException extends SecurityTokenInval…
c2c75b3
Removed duplicated tests
87b7d8c
Suppress the obsolete warning CS0618
ca9e0be
Rid of cloudInstanceName parameter for extension method
7787c39
Extracted conditions to improve readability
0bc2682
call ValidateSigningKeyCloudInstanceName before custom delegates
b17bf07
Reverted changes in JsonWebTokenHandler.ValidateSignatureTests.cs
alexholub113 fbb025c
Renamed exception
52e7cc4
Added GetJsonWebKeyBySecurityKey that using a loop to find a key
afbe421
Renamed CloudInstanceName to CloudInstance for public members
fd5fec7
Reverted renaming of ValidateIssuerSigningKeyTests to avoid breaking …
41679b7
Fix tests by create new instance of TokenValidationParameters in orde…
4520819
Assigned delegates properly to avoid infinite recursion
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
92 changes: 92 additions & 0 deletions
92
src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenInvalidCloudInstanceException.cs
This file contains hidden or 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,92 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Microsoft.IdentityModel.Tokens | ||
{ | ||
/// <summary> | ||
/// This exception is thrown when specific cloud instance was not matched with cloud instance of signing key. | ||
/// </summary> | ||
[Serializable] | ||
public class SecurityTokenInvalidCloudInstanceException : SecurityTokenInvalidSigningKeyException | ||
{ | ||
[NonSerialized] | ||
const string _Prefix = "Microsoft.IdentityModel." + nameof(SecurityTokenInvalidCloudInstanceException) + "."; | ||
|
||
[NonSerialized] | ||
const string _InvalidCloudInstanceKey = _Prefix + nameof(InvalidCloudInstance); | ||
|
||
/// <summary> | ||
/// Gets or sets the invalid cloud instance that created the validation exception. | ||
/// </summary> | ||
public string InvalidCloudInstance { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SecurityTokenInvalidCloudInstanceException"/> class. | ||
/// </summary> | ||
public SecurityTokenInvalidCloudInstanceException() | ||
: base() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SecurityTokenInvalidCloudInstanceException"/> class. | ||
/// </summary> | ||
/// <param name="message">Addtional information to be included in the exception and displayed to user.</param> | ||
public SecurityTokenInvalidCloudInstanceException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SecurityTokenInvalidCloudInstanceException"/> class. | ||
/// </summary> | ||
/// <param name="message">Addtional information to be included in the exception and displayed to user.</param> | ||
/// <param name="innerException">A <see cref="Exception"/> that represents the root cause of the exception.</param> | ||
public SecurityTokenInvalidCloudInstanceException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SecurityTokenInvalidCloudInstanceException"/> class. | ||
/// </summary> | ||
/// <param name="info">the <see cref="SerializationInfo"/> that holds the serialized object data.</param> | ||
/// <param name="context">The contextual information about the source or destination.</param> | ||
#if NET8_0_OR_GREATER | ||
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] | ||
#endif | ||
protected SecurityTokenInvalidCloudInstanceException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
SerializationInfoEnumerator enumerator = info.GetEnumerator(); | ||
while (enumerator.MoveNext()) | ||
{ | ||
switch (enumerator.Name) | ||
{ | ||
case _InvalidCloudInstanceKey: | ||
InvalidCloudInstance = info.GetString(_InvalidCloudInstanceKey); | ||
break; | ||
|
||
default: | ||
// Ignore other fields. | ||
break; | ||
} | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
#if NET8_0_OR_GREATER | ||
[Obsolete("Formatter-based serialization is obsolete", DiagnosticId = "SYSLIB0051")] | ||
#endif | ||
public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
{ | ||
base.GetObjectData(info, context); | ||
|
||
if (!string.IsNullOrEmpty(InvalidCloudInstance)) | ||
info.AddValue(_InvalidCloudInstanceKey, InvalidCloudInstance); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.