diff --git a/benchmark/Microsoft.IdentityModel.Benchmarks/ClaimsIdentityTests.cs b/benchmark/Microsoft.IdentityModel.Benchmarks/ClaimsIdentityTests.cs index 70c6ba810a..c7a3d04d4a 100644 --- a/benchmark/Microsoft.IdentityModel.Benchmarks/ClaimsIdentityTests.cs +++ b/benchmark/Microsoft.IdentityModel.Benchmarks/ClaimsIdentityTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.IdentityModel.Benchmarks public class ClaimsIdentityTests { private ClaimsIdentity _claimsIdentity; - private NewClaimsIdentity _jwtClaimsIdentity; + private NewClaimsIdentity _newClaimsIdentity; private string _claimTypeToFind; private string _claimValueToFind; private Predicate _findPredicate; @@ -25,7 +25,7 @@ public class ClaimsIdentityTests private JsonWebTokenHandler _jsonWebTokenHandler; private string _jwsWithExtendedClaims; private TokenValidationParameters _tokenValidationParameters; - private TokenValidationParameters _jwtTokenValidationParameters; + private TokenValidationParameters _newTokenValidationParameters; [GlobalSetup] public async Task SetupAsync() @@ -43,7 +43,7 @@ public async Task SetupAsync() ValidIssuer = BenchmarkUtils.Issuer, IssuerSigningKey = BenchmarkUtils.SigningCredentialsRsaSha256.Key, }; - _jwtTokenValidationParameters = new TokenValidationParameters() + _newTokenValidationParameters = new TokenValidationParameters() { ValidAudience = BenchmarkUtils.Audience, ValidateLifetime = true, @@ -58,7 +58,7 @@ public async Task SetupAsync() _hasClaimPredicate = claim => claim.Type == _claimTypeToFind && claim.Value == _claimValueToFind; _claimsIdentity = (await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _tokenValidationParameters).ConfigureAwait(false)).ClaimsIdentity; - _jwtClaimsIdentity = (await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _jwtTokenValidationParameters).ConfigureAwait(false)).ClaimsIdentity as NewClaimsIdentity; + _newClaimsIdentity = (await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _newTokenValidationParameters).ConfigureAwait(false)).ClaimsIdentity as NewClaimsIdentity; } [Benchmark(Baseline = true), BenchmarkCategory("FindFirst")] @@ -104,44 +104,44 @@ public bool ClaimsIdentity_HasClaim_WithPredicate() } [Benchmark, BenchmarkCategory("FindFirst")] - public Claim JwtClaimsIdentity_FindFirst() + public Claim NewClaimsIdentity_FindFirst() { - var temp = _jwtClaimsIdentity.FindFirst(_claimTypeToFind); + var temp = _newClaimsIdentity.FindFirst(_claimTypeToFind); return temp; } [Benchmark, BenchmarkCategory("FindFirstPredicate")] - public Claim JwtClaimsIdentity_FindFirst_WithPredicate() + public Claim NewClaimsIdentity_FindFirst_WithPredicate() { - var temp = _jwtClaimsIdentity.FindFirst(_findPredicate); + var temp = _newClaimsIdentity.FindFirst(_findPredicate); return temp; } [Benchmark, BenchmarkCategory("FindAll")] - public List JwtClaimsIdentity_FindAll() + public List NewClaimsIdentity_FindAll() { - var temp = _jwtClaimsIdentity.FindAll(_claimTypeToFind).ToList(); + var temp = _newClaimsIdentity.FindAll(_claimTypeToFind).ToList(); return temp; } [Benchmark, BenchmarkCategory("FindAllPredicate")] - public List JwtClaimsIdentity_FindAll_WithPredicate() + public List NewClaimsIdentity_FindAll_WithPredicate() { - var temp = _jwtClaimsIdentity.FindAll(_findPredicate).ToList(); + var temp = _newClaimsIdentity.FindAll(_findPredicate).ToList(); return temp; } [Benchmark, BenchmarkCategory("HasClaim")] - public bool JwtClaimsIdentity_HasClaim() + public bool NewClaimsIdentity_HasClaim() { - var temp = _jwtClaimsIdentity.HasClaim(_claimTypeToFind, _claimValueToFind); + var temp = _newClaimsIdentity.HasClaim(_claimTypeToFind, _claimValueToFind); return temp; } [Benchmark, BenchmarkCategory("HasClaimPredicate")] - public bool JwtClaimsIdentity_HasClaim_WithPredicate() + public bool NewClaimsIdentity_HasClaim_WithPredicate() { - var temp = _jwtClaimsIdentity.HasClaim(_hasClaimPredicate); + var temp = _newClaimsIdentity.HasClaim(_hasClaimPredicate); return temp; } @@ -155,9 +155,9 @@ public async Task> ClaimsIdentity_ValidateTokenAndGetClaims() } [Benchmark, BenchmarkCategory("ValidateAndGetClaims")] - public async Task> JwtClaimsIdentity_ValidateTokenAndGetClaims() + public async Task> NewClaimsIdentity_ValidateTokenAndGetClaims() { - var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _jwtTokenValidationParameters).ConfigureAwait(false); + var result = await _jsonWebTokenHandler.ValidateTokenAsync(_jwsWithExtendedClaims, _newTokenValidationParameters).ConfigureAwait(false); var claimsIdentity = result.ClaimsIdentity; var claims = claimsIdentity.Claims; return claims.ToList(); diff --git a/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs b/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs index 2880fbba93..6c0eded548 100644 --- a/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs +++ b/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs @@ -243,7 +243,8 @@ public virtual ClaimsIdentity CreateClaimsIdentity(SecurityToken securityToken, authenticationType: AuthenticationType ?? DefaultAuthenticationType, nameType: nameClaimType ?? ClaimsIdentity.DefaultNameClaimType, roleType: roleClaimType ?? ClaimsIdentity.DefaultRoleClaimType, - securityToken); + securityToken, + this); } ///