| | | 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.Generic; |
| | | 6 | | using System.Collections.ObjectModel; |
| | | 7 | | using CoreWCF.IdentityModel.Claims; |
| | | 8 | | using CoreWCF.Security; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.IdentityModel.Policy |
| | | 11 | | { |
| | | 12 | | internal class DefaultEvaluationContext : EvaluationContext |
| | | 13 | | { |
| | | 14 | | private List<ClaimSet> _claimSets; |
| | | 15 | | private readonly Dictionary<string, object> _properties; |
| | | 16 | | private int _generation; |
| | | 17 | | private ReadOnlyCollection<ClaimSet> _readOnlyClaimSets; |
| | | 18 | | |
| | 106 | 19 | | public DefaultEvaluationContext() |
| | | 20 | | { |
| | 106 | 21 | | _properties = new Dictionary<string, object>(); |
| | 106 | 22 | | _generation = 0; |
| | 106 | 23 | | } |
| | | 24 | | |
| | | 25 | | public override int Generation |
| | | 26 | | { |
| | 134 | 27 | | get { return _generation; } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | public override ReadOnlyCollection<ClaimSet> ClaimSets |
| | | 31 | | { |
| | | 32 | | get |
| | | 33 | | { |
| | 106 | 34 | | if (_claimSets == null) |
| | | 35 | | { |
| | 88 | 36 | | return EmptyReadOnlyCollection<ClaimSet>.Instance; |
| | | 37 | | } |
| | | 38 | | |
| | 18 | 39 | | if (_readOnlyClaimSets == null) |
| | | 40 | | { |
| | 18 | 41 | | _readOnlyClaimSets = new ReadOnlyCollection<ClaimSet>(_claimSets); |
| | | 42 | | } |
| | | 43 | | |
| | 18 | 44 | | return _readOnlyClaimSets; |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public override IDictionary<string, object> Properties |
| | | 49 | | { |
| | 257 | 50 | | get { return _properties; } |
| | | 51 | | } |
| | | 52 | | |
| | 220 | 53 | | public DateTime ExpirationTime { get; private set; } = SecurityUtils.MaxUtcDateTime; |
| | | 54 | | |
| | | 55 | | public override void AddClaimSet(IAuthorizationPolicy policy, ClaimSet claimSet) |
| | | 56 | | { |
| | 18 | 57 | | if (claimSet == null) |
| | | 58 | | { |
| | 0 | 59 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(claimSet)); |
| | | 60 | | } |
| | | 61 | | |
| | 18 | 62 | | if (_claimSets == null) |
| | | 63 | | { |
| | 18 | 64 | | _claimSets = new List<ClaimSet>(); |
| | | 65 | | } |
| | | 66 | | |
| | 18 | 67 | | _claimSets.Add(claimSet); |
| | 18 | 68 | | ++_generation; |
| | 18 | 69 | | } |
| | | 70 | | |
| | | 71 | | public override void RecordExpirationTime(DateTime expirationTime) |
| | | 72 | | { |
| | 4 | 73 | | if (ExpirationTime > expirationTime) |
| | | 74 | | { |
| | 4 | 75 | | ExpirationTime = expirationTime; |
| | | 76 | | } |
| | 4 | 77 | | } |
| | | 78 | | } |
| | | 79 | | } |