Skip to content

Commit

Permalink
Fix Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
sruke authored and brentschmaltz committed Oct 13, 2022
1 parent a8b18ca commit 5991e0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
23 changes: 10 additions & 13 deletions src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -253,14 +254,14 @@ protected TokenValidationParameters(TokenValidationParameters other)
ValidIssuer = other.ValidIssuer;
ValidIssuers = other.ValidIssuers;
ValidTypes = other.ValidTypes;
LogAllPolicyFailuresAsError = other.LogAllPolicyFailuresAsError;
}

/// <summary>
/// Initializes a new instance of the <see cref="TokenValidationParameters"/> class.
/// </summary>
public TokenValidationParameters()
{
LogValidationExceptions = true;
RequireExpirationTime = true;
RequireSignedTokens = true;
RequireAudience = true;
Expand All @@ -272,7 +273,6 @@ public TokenValidationParameters()
ValidateIssuerSigningKey = false;
ValidateLifetime = true;
ValidateTokenReplay = false;
LogAllPolicyFailuresAsError = true;
}

/// <summary>
Expand Down Expand Up @@ -525,6 +525,14 @@ public virtual ClaimsIdentity CreateClaimsIdentity(SecurityToken securityToken,
/// </remarks>
public LifetimeValidator LifetimeValidator { get; set; }

/// <summary>
/// Gets or sets a <see cref="bool"/> that will decide if validation failure needs to be logged as an error.
/// Default value is <c>true</c> for backward compatibility of the behavior.
/// If set to false, validation failures are logged as Information and then thrown.
/// </summary>
[DefaultValue(true)]
public bool LogValidationExceptions { get; set; }

/// <summary>
/// Gets or sets a <see cref="string"/> that defines the <see cref="ClaimsIdentity.NameClaimType"/>.
/// </summary>
Expand Down Expand Up @@ -833,16 +841,5 @@ public string RoleClaimType
/// The default is <c>null</c>.
/// </summary>
public IEnumerable<string> ValidTypes { get; set; }

/// <summary>
/// Gets or sets a <see cref="bool"/> that will decide if cause of a policy failure needs to be logged as an error.
/// Default value is <c>true</c> for backward compatibility of the behavior.
/// If set to false, exceptions are logged as Information and then thrown.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[DefaultValue(true)]
public bool LogAllPolicyFailuresAsError { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Microsoft.IdentityModel.Tokens/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void ValidateAudience(IEnumerable<string> audiences, SecurityToken
LogHelper.MarkAsNonPII(Utility.SerializeAsSingleCommaDelimitedString(validationParameters.ValidAudiences))))
{ InvalidAudience = Utility.SerializeAsSingleCommaDelimitedString(audiences) };

if (!validationParameters.LogAllPolicyFailuresAsError)
if (!validationParameters.LogValidationExceptions)
throw ex;

throw LogHelper.LogExceptionMessage(ex);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void Publics()
IssuerSigningKeys = issuerSigningKeys,
IssuerValidator = ValidationDelegates.IssuerValidatorEcho,
LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue,
LogValidationExceptions = true,
PropertyBag = propertyBag,
SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs,
SaveSigninToken = true,
Expand All @@ -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));
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 5991e0f

Please # to comment.