| | | 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 CoreWCF.Channels; |
| | | 7 | | using CoreWCF.Security.Tokens; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Security |
| | | 10 | | { |
| | | 11 | | internal class SecurityTokenParametersEnumerable : IEnumerable<SecurityTokenParameters> |
| | | 12 | | { |
| | | 13 | | private readonly SecurityBindingElement _sbe; |
| | | 14 | | private readonly bool _clientTokensOnly; |
| | | 15 | | |
| | | 16 | | public SecurityTokenParametersEnumerable(SecurityBindingElement sbe) |
| | 44 | 17 | | : this(sbe, false) { } |
| | | 18 | | |
| | 44 | 19 | | public SecurityTokenParametersEnumerable(SecurityBindingElement sbe, bool clientTokensOnly) |
| | | 20 | | { |
| | 44 | 21 | | _sbe = sbe ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(sbe)); |
| | 44 | 22 | | _clientTokensOnly = clientTokensOnly; |
| | 44 | 23 | | } |
| | | 24 | | |
| | | 25 | | public IEnumerator<SecurityTokenParameters> GetEnumerator() |
| | | 26 | | { |
| | 44 | 27 | | if (_sbe is SymmetricSecurityBindingElement) |
| | | 28 | | { |
| | 0 | 29 | | SymmetricSecurityBindingElement ssbe = (SymmetricSecurityBindingElement)_sbe; |
| | 0 | 30 | | if (ssbe.ProtectionTokenParameters != null && (!_clientTokensOnly || !ssbe.ProtectionTokenParameters.Has |
| | | 31 | | { |
| | 0 | 32 | | yield return ssbe.ProtectionTokenParameters; |
| | | 33 | | } |
| | | 34 | | } |
| | | 35 | | // TODO |
| | | 36 | | /* else if (this.sbe is AsymmetricSecurityBindingElement) |
| | | 37 | | { |
| | | 38 | | AsymmetricSecurityBindingElement asbe = (AsymmetricSecurityBindingElement)sbe; |
| | | 39 | | if (asbe.InitiatorTokenParameters != null) |
| | | 40 | | yield return asbe.InitiatorTokenParameters; |
| | | 41 | | if (asbe.RecipientTokenParameters != null && !this.clientTokensOnly) |
| | | 42 | | yield return asbe.RecipientTokenParameters; |
| | | 43 | | }*/ |
| | 143 | 44 | | foreach (SecurityTokenParameters stp in _sbe.EndpointSupportingTokenParameters.Endorsing) |
| | | 45 | | { |
| | 32 | 46 | | if (stp != null) |
| | | 47 | | { |
| | 32 | 48 | | yield return stp; |
| | | 49 | | } |
| | | 50 | | } |
| | | 51 | | |
| | 94 | 52 | | foreach (SecurityTokenParameters stp in _sbe.EndpointSupportingTokenParameters.SignedEncrypted) |
| | | 53 | | { |
| | 12 | 54 | | if (stp != null) |
| | | 55 | | { |
| | 12 | 56 | | yield return stp; |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | |
| | 70 | 60 | | foreach (SecurityTokenParameters stp in _sbe.EndpointSupportingTokenParameters.SignedEndorsing) |
| | | 61 | | { |
| | 0 | 62 | | if (stp != null) |
| | | 63 | | { |
| | 0 | 64 | | yield return stp; |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | |
| | 70 | 68 | | foreach (SecurityTokenParameters stp in _sbe.EndpointSupportingTokenParameters.Signed) |
| | | 69 | | { |
| | 0 | 70 | | if (stp != null) |
| | | 71 | | { |
| | 0 | 72 | | yield return stp; |
| | | 73 | | } |
| | | 74 | | } |
| | | 75 | | |
| | 70 | 76 | | foreach (SupportingTokenParameters str in _sbe.OperationSupportingTokenParameters.Values) |
| | | 77 | | { |
| | 0 | 78 | | if (str != null) |
| | | 79 | | { |
| | 0 | 80 | | foreach (SecurityTokenParameters stp in str.Endorsing) |
| | | 81 | | { |
| | 0 | 82 | | if (stp != null) |
| | | 83 | | { |
| | 0 | 84 | | yield return stp; |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | |
| | 0 | 88 | | foreach (SecurityTokenParameters stp in str.SignedEncrypted) |
| | | 89 | | { |
| | 0 | 90 | | if (stp != null) |
| | | 91 | | { |
| | 0 | 92 | | yield return stp; |
| | | 93 | | } |
| | | 94 | | } |
| | | 95 | | |
| | 0 | 96 | | foreach (SecurityTokenParameters stp in str.SignedEndorsing) |
| | | 97 | | { |
| | 0 | 98 | | if (stp != null) |
| | | 99 | | { |
| | 0 | 100 | | yield return stp; |
| | | 101 | | } |
| | | 102 | | } |
| | | 103 | | |
| | 0 | 104 | | foreach (SecurityTokenParameters stp in str.Signed) |
| | | 105 | | { |
| | 0 | 106 | | if (stp != null) |
| | | 107 | | { |
| | 0 | 108 | | yield return stp; |
| | | 109 | | } |
| | | 110 | | } |
| | | 111 | | } |
| | 0 | 112 | | } |
| | 35 | 113 | | } |
| | | 114 | | |
| | | 115 | | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
| | | 116 | | { |
| | 0 | 117 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); |
| | | 118 | | } |
| | | 119 | | } |
| | | 120 | | } |