From 5991e0f3eae715f23b8a15ab4a353660da81427c Mon Sep 17 00:00:00 2001
From: sruke <73967733+sruke@users.noreply.github.com>
Date: Thu, 13 Oct 2022 11:01:29 -0700
Subject: [PATCH] Fix Naming
---
.../TokenValidationParameters.cs | 23 ++++++++-----------
.../Validators.cs | 4 ++--
.../TokenValidationParametersTests.cs | 8 +++----
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs b/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs
index 1682344261..d1f6dbcc06 100644
--- a/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs
+++ b/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs
@@ -219,6 +219,7 @@ protected TokenValidationParameters(TokenValidationParameters other)
IssuerSigningKeyValidator = other.IssuerSigningKeyValidator;
IssuerValidator = other.IssuerValidator;
LifetimeValidator = other.LifetimeValidator;
+ LogValidationExceptions = other.LogValidationExceptions;
NameClaimType = other.NameClaimType;
NameClaimTypeRetriever = other.NameClaimTypeRetriever;
PropertyBag = other.PropertyBag;
@@ -253,7 +254,6 @@ protected TokenValidationParameters(TokenValidationParameters other)
ValidIssuer = other.ValidIssuer;
ValidIssuers = other.ValidIssuers;
ValidTypes = other.ValidTypes;
- LogAllPolicyFailuresAsError = other.LogAllPolicyFailuresAsError;
}
///
@@ -261,6 +261,7 @@ protected TokenValidationParameters(TokenValidationParameters other)
///
public TokenValidationParameters()
{
+ LogValidationExceptions = true;
RequireExpirationTime = true;
RequireSignedTokens = true;
RequireAudience = true;
@@ -272,7 +273,6 @@ public TokenValidationParameters()
ValidateIssuerSigningKey = false;
ValidateLifetime = true;
ValidateTokenReplay = false;
- LogAllPolicyFailuresAsError = true;
}
///
@@ -525,6 +525,14 @@ public virtual ClaimsIdentity CreateClaimsIdentity(SecurityToken securityToken,
///
public LifetimeValidator LifetimeValidator { get; set; }
+ ///
+ /// Gets or sets a that will decide if validation failure needs to be logged as an error.
+ /// Default value is true for backward compatibility of the behavior.
+ /// If set to false, validation failures are logged as Information and then thrown.
+ ///
+ [DefaultValue(true)]
+ public bool LogValidationExceptions { get; set; }
+
///
/// Gets or sets a that defines the .
///
@@ -833,16 +841,5 @@ public string RoleClaimType
/// The default is null.
///
public IEnumerable ValidTypes { get; set; }
-
- ///
- /// Gets or sets a that will decide if cause of a policy failure needs to be logged as an error.
- /// Default value is true for backward compatibility of the behavior.
- /// If set to false, exceptions are logged as Information and then thrown.
- ///
- ///
- /// When multiple polices are defined, all of them are tried until one succeeds and setting this property to false will reduce the noise in the logs.
- ///
- [DefaultValue(true)]
- public bool LogAllPolicyFailuresAsError { get; set; }
}
}
diff --git a/src/Microsoft.IdentityModel.Tokens/Validators.cs b/src/Microsoft.IdentityModel.Tokens/Validators.cs
index 4601354ce8..0c3807e0d2 100644
--- a/src/Microsoft.IdentityModel.Tokens/Validators.cs
+++ b/src/Microsoft.IdentityModel.Tokens/Validators.cs
@@ -112,7 +112,7 @@ public static void ValidateAudience(IEnumerable audiences, SecurityToken
LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validationParameters.ValidAudiences))))
{ InvalidAudience = Utility.SerializeAsSingleCommaDelimitedString(audiences) };
- if (!validationParameters.LogAllPolicyFailuresAsError)
+ if (!validationParameters.LogValidationExceptions)
throw ex;
throw LogHelper.LogExceptionMessage(ex);
@@ -274,7 +274,7 @@ internal static string ValidateIssuer(string issuer, SecurityToken securityToken
LogHelper.MarkAsNonPII(configuration?.Issuer)))
{ InvalidIssuer = issuer };
- if (!validationParameters.LogAllPolicyFailuresAsError)
+ if (!validationParameters.LogValidationExceptions)
throw ex;
throw LogHelper.LogExceptionMessage(ex);
diff --git a/test/Microsoft.IdentityModel.Tokens.Tests/TokenValidationParametersTests.cs b/test/Microsoft.IdentityModel.Tokens.Tests/TokenValidationParametersTests.cs
index 96a2183520..98971edfd4 100644
--- a/test/Microsoft.IdentityModel.Tokens.Tests/TokenValidationParametersTests.cs
+++ b/test/Microsoft.IdentityModel.Tokens.Tests/TokenValidationParametersTests.cs
@@ -71,6 +71,7 @@ public void Publics()
IssuerSigningKeys = issuerSigningKeys,
IssuerValidator = ValidationDelegates.IssuerValidatorEcho,
LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue,
+ LogValidationExceptions = true,
PropertyBag = propertyBag,
SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs,
SaveSigninToken = true,
@@ -82,8 +83,7 @@ public void Publics()
ValidAudiences = validAudiences,
ValidIssuer = validIssuer,
ValidIssuers = validIssuers,
- ValidTypes = validTypes,
- LogAllPolicyFailuresAsError = true
+ ValidTypes = validTypes
};
Assert.True(object.ReferenceEquals(actorValidationParameters, validationParametersInline.ActorValidationParameters));
@@ -109,6 +109,7 @@ public void Publics()
validationParametersSets.IssuerSigningKeys = issuerSigningKeysDup;
validationParametersSets.IssuerValidator = ValidationDelegates.IssuerValidatorEcho;
validationParametersSets.LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue;
+ validationParametersSets.LogValidationExceptions = true;
validationParametersSets.PropertyBag = propertyBag;
validationParametersSets.SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs;
validationParametersSets.SaveSigninToken = true;
@@ -121,8 +122,7 @@ public void Publics()
validationParametersSets.ValidIssuer = validIssuer;
validationParametersSets.ValidIssuers = validIssuers;
validationParametersSets.ValidTypes = validTypes;
- validationParametersSets.LogAllPolicyFailuresAsError = true;
-
+
var compareContext = new CompareContext();
IdentityComparer.AreEqual(validationParametersInline, validationParametersSets, compareContext);
IdentityComparer.AreEqual(validationParametersInline.Clone() as TokenValidationParameters, validationParametersInline, compareContext);