protected void OnBeforeAccess(CredentialCacheNotificationArgs args) { if (this.BeforeAccess != null) { this.BeforeAccess(args); } }
protected void OnBeforeWrite(CredentialCacheNotificationArgs args) { if (this.BeforeWrite != null) { this.BeforeWrite(args); } }
/// <summary> /// Clears the cache contents. /// </summary> public virtual void Clear() { var cacheNotificationArgs = new CredentialCacheNotificationArgs { CredentialCache = this }; this.OnBeforeAccess(cacheNotificationArgs); this.OnBeforeWrite(cacheNotificationArgs); this.cacheDictionary.Clear(); this.HasStateChanged = true; this.OnAfterAccess(cacheNotificationArgs); }
/// <summary> /// Clears the cache contents. /// </summary> public override void Clear() { // ADAL caching doesn't notify the delegates of access on Clear(). Call them explicitly // for consistency with CredentialCache behavior since the cache is being accessed and written. var cacheNotificationArgs = new CredentialCacheNotificationArgs { CredentialCache = this }; this.OnBeforeAccess(cacheNotificationArgs); this.OnBeforeWrite(cacheNotificationArgs); this.TokenCache.Clear(); this.OnAfterAccess(cacheNotificationArgs); this.HasStateChanged = true; }
internal virtual void AddToCache(AccountSession accountSession) { var cacheNotificationArgs = new CredentialCacheNotificationArgs { CredentialCache = this }; this.OnBeforeAccess(cacheNotificationArgs); this.OnBeforeWrite(cacheNotificationArgs); var cacheKey = this.GetKeyForAuthResult(accountSession); this.cacheDictionary[cacheKey] = accountSession; this.MostRecentlyUsedKey = cacheKey; this.HasStateChanged = true; this.OnAfterAccess(cacheNotificationArgs); }
/// <summary> /// Gets the most recently read or written result from cache. /// </summary> /// <returns>Most recently used result. Null if no cache value is stored /// as most recently used (could be that most-recently used value was deleted). /// </returns> internal virtual AccountSession GetMostRecentlyUsedResultFromCache() { var cacheNotificationArgs = new CredentialCacheNotificationArgs { CredentialCache = this }; this.OnBeforeAccess(cacheNotificationArgs); if (this.MostRecentlyUsedKey == null) { return(null); } var result = this.GetResultFromCache(this.MostRecentlyUsedKey); this.OnAfterAccess(cacheNotificationArgs); return(result); }
internal virtual AccountSession GetResultFromCache(string clientId, string userId) { var credentialCacheKey = new CredentialCacheKey { ClientId = clientId, UserId = userId, }; var cacheNotificationArgs = new CredentialCacheNotificationArgs { CredentialCache = this }; this.OnBeforeAccess(cacheNotificationArgs); var result = this.GetResultFromCache(credentialCacheKey); this.OnAfterAccess(cacheNotificationArgs); return(result); }
internal virtual void DeleteFromCache(AccountSession accountSession) { if (accountSession != null) { var cacheNotificationArgs = new CredentialCacheNotificationArgs { CredentialCache = this }; this.OnBeforeAccess(cacheNotificationArgs); this.OnBeforeWrite(cacheNotificationArgs); var credentialCacheKey = this.GetKeyForAuthResult(accountSession); this.cacheDictionary.Remove(credentialCacheKey); if (credentialCacheKey.Equals(this.MostRecentlyUsedKey)) { this.MostRecentlyUsedKey = null; } this.HasStateChanged = true; this.OnAfterAccess(cacheNotificationArgs); } }