public BinaryBlob ExtractClaimUid(IIdentity identity) { if ( identity == null || !identity.IsAuthenticated || _config.SuppressIdentityHeuristicChecks ) { // Skip anonymous users // Skip when claims-based checks are disabled return(null); } ClaimsIdentity claimsIdentity = _claimsIdentityConverter.TryConvert(identity); if (claimsIdentity == null) { // not a claims-based identity return(null); } string[] uniqueIdentifierParameters = GetUniqueIdentifierParameters( claimsIdentity, _config.UniqueClaimTypeIdentifier ); byte[] claimUidBytes = CryptoUtil.ComputeSHA256(uniqueIdentifierParameters); return(new BinaryBlob(256, claimUidBytes)); }
public void TryConvert_NoMatches_ReturnsNull() { // Arrange IIdentity identity = new Mock <IIdentity>().Object; ClaimsIdentityConverter converter = new ClaimsIdentityConverter(new Func <IIdentity, ClaimsIdentity> [0]); // Act ClaimsIdentity retVal = converter.TryConvert(identity); // Assert Assert.Null(retVal); }
public void TryConvert_NoMatches_ReturnsNull() { // Arrange IIdentity identity = new Mock<IIdentity>().Object; ClaimsIdentityConverter converter = new ClaimsIdentityConverter(new Func<IIdentity, ClaimsIdentity>[0]); // Act ClaimsIdentity retVal = converter.TryConvert(identity); // Assert Assert.Null(retVal); }
public void TryConvert_SkipsGrandfatheredTypes(IIdentity identity) { // Arrange ClaimsIdentityConverter converter = new ClaimsIdentityConverter(new Func <IIdentity, ClaimsIdentity>[] { _ => { throw new Exception("Should never be called."); } }); // Act ClaimsIdentity retVal = converter.TryConvert(identity); // Assert Assert.Null(retVal); }
public void TryConvert_SkipsGrandfatheredTypes(IIdentity identity) { // Arrange ClaimsIdentityConverter converter = new ClaimsIdentityConverter(new Func<IIdentity, ClaimsIdentity>[] { _ => { throw new Exception("Should never be called."); } }); // Act ClaimsIdentity retVal = converter.TryConvert(identity); // Assert Assert.Null(retVal); }
public void TryConvert_ReturnsFirstMatch() { // Arrange IIdentity identity = new Mock <IIdentity>().Object; ClaimsIdentity claimsIdentity = new MockClaimsIdentity(); ClaimsIdentityConverter converter = new ClaimsIdentityConverter(new Func <IIdentity, ClaimsIdentity>[] { _ => null, i => (i == identity) ? claimsIdentity : null }); // Act ClaimsIdentity retVal = converter.TryConvert(identity); // Assert Assert.Same(claimsIdentity, retVal); }
public void TryConvert_ReturnsFirstMatch() { // Arrange IIdentity identity = new Mock<IIdentity>().Object; ClaimsIdentity claimsIdentity = new MockClaimsIdentity(); ClaimsIdentityConverter converter = new ClaimsIdentityConverter(new Func<IIdentity, ClaimsIdentity>[] { _ => null, i => (i == identity) ? claimsIdentity : null }); // Act ClaimsIdentity retVal = converter.TryConvert(identity); // Assert Assert.Same(claimsIdentity, retVal); }