private static bool AreEqual(TokenCacheItem item, TokenCacheKey key) { return item.Match(key); }
public void DeleteItemTest() { TokenCache tokenCache = TokenCacheHelper.CreateCacheWithItems(); try { tokenCache.DeleteItem(null); Assert.Fail("ArgumentNullException should have been thrown"); } catch (ArgumentNullException) { } KeyValuePair<TokenCacheKey, AuthenticationResultEx>? kvp = tokenCache.LoadSingleItemFromCache(TestConstants.DefaultAuthorityHomeTenant, TestConstants.DefaultScope, TestConstants.DefaultClientId, TestConstants.DefaultUser, TestConstants.DefaultPolicy, null); TokenCacheItem item = new TokenCacheItem(kvp.Value.Key, kvp.Value.Value.Result); tokenCache.DeleteItem(item); Assert.AreEqual(1, tokenCache.Count); IEnumerable<TokenCacheItem> items = tokenCache.ReadItems(TestConstants.DefaultClientId); Assert.AreEqual(TestConstants.DefaultUniqueId + "more", items.Where(entry => entry.Authority.Equals(TestConstants.DefaultAuthorityGuestTenant)).First().UniqueId); }
private void DeleteItemFromCache(TokenCacheItem item) { TokenCacheKey toRemoveKey = this.tokenCacheDictionary.Keys.FirstOrDefault(item.Match); if (toRemoveKey != null) { this.tokenCacheDictionary.Remove(toRemoveKey); } }
public void SaveToken(TokenCacheItem tokenItem) { throw new NotImplementedException(); }
/// <summary> /// Deletes an item from the cache. /// </summary> /// <param name="item">The item to delete from the cache</param> internal void DeleteItem(TokenCacheItem item) { lock (lockObject) { if (item == null) { throw new ArgumentNullException("item"); } PlatformPlugin.Logger.Information(null, "Deleting token in the cache"); TokenCacheNotificationArgs args = new TokenCacheNotificationArgs { TokenCache = this, Scope = item.Scope.AsArray(), ClientId = item.ClientId, User = item.User, Policy = item.Policy }; this.OnBeforeAccess(args); this.OnBeforeWrite(args); DeleteItemFromCache(item); this.HasStateChanged = true; this.OnAfterAccess(args); } }