Beispiel #1
0
        // clean up the DB
        public override void Clear()
        {
            base.Clear();
            IEnumerable <PerWebUserCache> entries = null;
            var task = Task.Run(async() => {
                entries = await PerWebUserCache.GetAllEntries();
            });

            task.Wait();

            foreach (var cacheEntry in entries)
            {
                PerWebUserCache.RemoveEntry(cacheEntry).Wait();
            }
        }
Beispiel #2
0
        // constructor
        public AdalCosmosTokenCache(string userObjId, string hostName)
        {
            // associate the cache to the current user of the web app
            _userObjId = userObjId;
            _hostName  = hostName;

            this.AfterAccess  = AfterAccessNotification;
            this.BeforeAccess = BeforeAccessNotification;
            this.BeforeWrite  = BeforeWriteNotification;

            // look up the entry in the DB
            var task = Task.Run(async() => {
                Cache = await PerWebUserCache.GetCache(new CacheUser(_userObjId, _hostName));
            });

            task.Wait();

            try
            {
                // place the entry in memory
                this.Deserialize((Cache == null) ? null : B2BPortal.Common.Utils.Utils.Decrypt(new EncryptedObj(Cache.CacheBits, Cache.Salt)));
            }
            catch (CryptographicException)
            {
                //error decrypting from token cache - clearing the cached item (encryption key may have changed)
                task = Task.Run(async() => {
                    await PerWebUserCache.RemoveEntry(Cache);
                });
                task.Wait();
                this.Deserialize(null);
            }
            catch (Exception ex)
            {
                var newEx = new Exception("Error decrypting the cached token. ", ex);
                throw newEx;
            }
        }