Exemplo n.º 1
0
 protected void OnBeforeAccess(CredentialCacheNotificationArgs args)
 {
     if (this.BeforeAccess != null)
     {
         this.BeforeAccess(args);
     }
 }
Exemplo n.º 2
0
 protected void OnBeforeWrite(CredentialCacheNotificationArgs args)
 {
     if (this.BeforeWrite != null)
     {
         this.BeforeWrite(args);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }