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); } }
public override void Remove(string key) { Purge(); _internalCache.Remove(key); ApiHelperAsync helper = new ApiHelperAsync(_httpClient); helper.Remove(key); }
public override void RemoveAll(string endpointId) { _internalCache.RemoveAll(endpointId); ApiHelperAsync helper = new ApiHelperAsync(_httpClient); helper.RemoveAllByEndpointId(new Endpoint() { EndpointId = endpointId }); }
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) }); }
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) }); }
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) }); }
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); }
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); }
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(); }
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); }
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); } }