예제 #1
0
 protected void OnBeforeAccess(CredentialCacheNotificationArgs args)
 {
     if (this.BeforeAccess != null)
     {
         this.BeforeAccess(args);
     }
 }
예제 #2
0
 protected void OnBeforeWrite(CredentialCacheNotificationArgs args)
 {
     if (this.BeforeWrite != null)
     {
         this.BeforeWrite(args);
     }
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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;
        }
예제 #5
0
        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);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
            }
        }