| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections; |
| | | 6 | | using CoreWCF.Runtime; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Security |
| | | 9 | | { |
| | | 10 | | internal sealed class NegotiationTokenAuthenticatorStateCache<T> : TimeBoundedCache |
| | | 11 | | where T : NegotiationTokenAuthenticatorState |
| | | 12 | | { |
| | 1 | 13 | | private static readonly int s_lowWaterMark = 50; |
| | | 14 | | private TimeSpan _cachingSpan; |
| | | 15 | | |
| | | 16 | | public NegotiationTokenAuthenticatorStateCache(TimeSpan cachingSpan, int maximumCachedState) |
| | 2 | 17 | | : base(s_lowWaterMark, maximumCachedState, null, PurgingMode.TimerBasedPurge, TimeSpan.FromTicks(cachingSpan |
| | | 18 | | |
| | | 19 | | public void AddState(string context, T state) |
| | | 20 | | { |
| | 0 | 21 | | DateTime expirationTime = TimeoutHelper.Add(DateTime.UtcNow, _cachingSpan); |
| | 0 | 22 | | bool wasStateAdded = base.TryAddItem(context, state, expirationTime, false); |
| | 0 | 23 | | if (!wasStateAdded) |
| | | 24 | | { |
| | 0 | 25 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityNegotiationException(SR.Format(S |
| | | 26 | | } |
| | | 27 | | //if (TD.NegotiateTokenAuthenticatorStateCacheRatioIsEnabled()) |
| | | 28 | | //{ |
| | | 29 | | // TD.NegotiateTokenAuthenticatorStateCacheRatio(base.Count, base.Capacity); |
| | | 30 | | //} |
| | 0 | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | public T GetState(string context) => (GetItem(context) as T); |
| | | 34 | | |
| | 0 | 35 | | public void RemoveState(string context) => TryRemoveItem(context);//if (TD.NegotiateTokenAuthenticatorStateCache |
| | | 36 | | |
| | | 37 | | |
| | | 38 | | protected override ArrayList OnQuotaReached(Hashtable cacheTable) => |
| | | 39 | | //if (TD.NegotiateTokenAuthenticatorStateCacheExceededIsEnabled()) |
| | | 40 | | //{ |
| | | 41 | | // TD.NegotiateTokenAuthenticatorStateCacheExceeded(SR.GetString(SR.CachedNegotiationStateQuotaReached, t |
| | | 42 | | //} |
| | 0 | 43 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QuotaExceededException(SR.Format(SR.CachedNego |
| | | 44 | | |
| | | 45 | | protected override void OnRemove(object item) |
| | | 46 | | { |
| | 0 | 47 | | ((IDisposable)item).Dispose(); |
| | 0 | 48 | | base.OnRemove(item); |
| | 0 | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |