示例#1
0
        public override void AddOrUpdate(SessionSecurityTokenCacheKey key, SessionSecurityToken value, DateTime expiryTime)
        {
            string         tokenId        = null;
            ApiHelperAsync helper         = new ApiHelperAsync(_httpClient);
            var            claimsIdentity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;

            if (claimsIdentity != null && claimsIdentity.BootstrapContext != null)
            {
                var bootstrap = claimsIdentity.BootstrapContext as BootstrapContext;
                if (bootstrap != null && bootstrap.SecurityToken != null)
                {
                    tokenId = bootstrap.SecurityToken.Id;
                }
            }
            if (tokenId == null || value == null)
            {
                return;
            }
            var res = helper.AddOrUpdate(new SessionCacheEntry()
            {
                EndpointId                = key.EndpointId,
                ContextId                 = GetContextIdString(key),
                KeyGeneration             = GetKeyGenerationString(key),
                ExpiryTime                = expiryTime,
                SessionSecurityTokenValue = value,
                UserName = Thread.CurrentPrincipal.Identity.Name,
                SessionSecurityTokenID = tokenId
            });

            if (res)
            {
                _internalCache.AddOrUpdate(key, value, expiryTime);
            }
        }
示例#2
0
        public override void Remove(string key)
        {
            Purge();

            _internalCache.Remove(key);

            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            helper.Remove(key);
        }
示例#3
0
        public override void RemoveAll(string endpointId)
        {
            _internalCache.RemoveAll(endpointId);

            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            helper.RemoveAllByEndpointId(new Endpoint()
            {
                EndpointId = endpointId
            });
        }
示例#4
0
        public override void RemoveAll(string endpointId, UniqueId contextId)
        {
            _internalCache.RemoveAll(endpointId, contextId);

            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            helper.RemoveAll(new Context()
            {
                EndpointId = endpointId,
                ContextId  = GetContextIdString(contextId)
            });
        }
示例#5
0
        public override void Remove(SessionSecurityTokenCacheKey key)
        {
            _internalCache.Remove(key);

            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            helper.Remove(new SessionCacheKey()
            {
                EndpointId    = key.EndpointId,
                ContextId     = GetContextIdString(key),
                KeyGeneration = GetKeyGenerationString(key)
            });
        }
示例#6
0
        public override void AddOrUpdate(string key, SecurityToken securityToken, DateTime expirationTime)
        {
            Purge();

            _internalCache.AddOrUpdate(key, securityToken, expirationTime);

            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            helper.AddOrUpdate(new ReplayCacheEntry()
            {
                Key            = key,
                ExpirationTime = expirationTime,
                SecurityToken  = securityToken.SerializeSecurityToken(_securityTokenSerializer)
            });
        }
示例#7
0
        public override bool Contains(string key)
        {
            Purge();

            if (!_internalCache.Contains(key))
            {
                ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

                var token = helper.Get(key);
                if (token != null && token.SecurityToken != null)
                {
                    _internalCache.AddOrUpdate(token.Key, token.SecurityToken.DeserializeSecurityToken(_securityTokenSerializer), token.ExpirationTime);
                    return(true);
                }
            }
            return(false);
        }
示例#8
0
        public override IEnumerable <SessionSecurityToken> GetAll(string endpointId, UniqueId contextId)
        {
#warning perhaps implement this for in memory
            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            var res = helper.GetAll(new Context()
            {
                EndpointId = endpointId,
                ContextId  = GetContextIdString(contextId)
            });

            foreach (var token in res)
            {
                SessionSecurityTokenCacheKey key = new SessionSecurityTokenCacheKey(endpointId, contextId, null);
                key.IgnoreKeyGeneration = true;
                _internalCache.AddOrUpdate(key, token, token.KeyExpirationTime);
            }
            return(res);
        }
示例#9
0
        void Purge()
        {
            if (_purgeInterval == TimeSpan.Zero)
            {
                return;
            }

            DateTime currentTime = DateTime.UtcNow;

            if (currentTime < _nextPurgeTime)
            {
                return;
            }

            _nextPurgeTime = currentTime.Add(_purgeInterval);

            ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

            helper.Purge();
        }
示例#10
0
        public override SessionSecurityToken Get(SessionSecurityTokenCacheKey key)
        {
            var resLocal = _internalCache.Get(key);

            if (resLocal == null)
            {
                ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

                var token = helper.Get(new SessionCacheKey()
                {
                    EndpointId    = key.EndpointId,
                    ContextId     = GetContextIdString(key),
                    KeyGeneration = GetKeyGenerationString(key)
                });

                if (token != null)
                {
                    resLocal = token;
                    _internalCache.AddOrUpdate(key, token, token.KeyExpirationTime);
                }
            }
            return(resLocal);
        }
示例#11
0
        public override SecurityToken Get(string key)
        {
            Purge();

            var localToken = _internalCache.Get(key);

            if (localToken == null)
            {
                ApiHelperAsync helper = new ApiHelperAsync(_httpClient);

                var token = helper.Get(key);
                if (token != null && token.SecurityToken != null)
                {
                    _internalCache.AddOrUpdate(token.Key, token.SecurityToken.DeserializeSecurityToken(_securityTokenSerializer), token.ExpirationTime);
                    return(_internalCache.Get(key));
                }
                return(null);
            }
            else
            {
                return(localToken);
            }
        }