| | | 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.Globalization; |
| | | 5 | | using System.Text; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | using CoreWCF.IdentityModel.Selectors; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Security.Tokens |
| | | 10 | | { |
| | | 11 | | public abstract class ServiceModelSecurityTokenRequirement : SecurityTokenRequirement |
| | | 12 | | { |
| | | 13 | | protected const string Namespace = "http://schemas.microsoft.com/ws/2006/05/servicemodel/securitytokenrequiremen |
| | | 14 | | private const string securityAlgorithmSuiteProperty = Namespace + "/SecurityAlgorithmSuite"; |
| | | 15 | | private const string securityBindingElementProperty = Namespace + "/SecurityBindingElement"; |
| | | 16 | | private const string issuerAddressProperty = Namespace + "/IssuerAddress"; |
| | | 17 | | private const string issuerBindingProperty = Namespace + "/IssuerBinding"; |
| | | 18 | | private const string secureConversationSecurityBindingElementProperty = Namespace + "/SecureConversationSecurity |
| | | 19 | | private const string supportSecurityContextCancellationProperty = Namespace + "/SupportSecurityContextCancellati |
| | | 20 | | private const string messageSecurityVersionProperty = Namespace + "/MessageSecurityVersion"; |
| | | 21 | | private const string defaultMessageSecurityVersionProperty = Namespace + "/DefaultMessageSecurityVersion"; |
| | | 22 | | private const string issuerBindingContextProperty = Namespace + "/IssuerBindingContext"; |
| | | 23 | | private const string transportSchemeProperty = Namespace + "/TransportScheme"; |
| | | 24 | | private const string isInitiatorProperty = Namespace + "/IsInitiator"; |
| | | 25 | | private const string targetAddressProperty = Namespace + "/TargetAddress"; |
| | | 26 | | private const string viaProperty = Namespace + "/Via"; |
| | | 27 | | private const string listenUriProperty = Namespace + "/ListenUri"; |
| | | 28 | | private const string auditLogLocationProperty = Namespace + "/AuditLogLocation"; |
| | | 29 | | private const string suppressAuditFailureProperty = Namespace + "/SuppressAuditFailure"; |
| | | 30 | | private const string messageAuthenticationAuditLevelProperty = Namespace + "/MessageAuthenticationAuditLevel"; |
| | | 31 | | private const string isOutOfBandTokenProperty = Namespace + "/IsOutOfBandToken"; |
| | | 32 | | private const string preferSslCertificateAuthenticatorProperty = Namespace + "/PreferSslCertificateAuthenticator |
| | | 33 | | |
| | | 34 | | // the following properties dont have top level OM properties but are part of the property bag |
| | | 35 | | private const string supportingTokenAttachmentModeProperty = Namespace + "/SupportingTokenAttachmentMode"; |
| | | 36 | | private const string messageDirectionProperty = Namespace + "/MessageDirection"; |
| | | 37 | | private const string httpAuthenticationSchemeProperty = Namespace + "/HttpAuthenticationScheme"; |
| | | 38 | | private const string issuedSecurityTokenParametersProperty = Namespace + "/IssuedSecurityTokenParameters"; |
| | | 39 | | private const string privacyNoticeUriProperty = Namespace + "/PrivacyNoticeUri"; |
| | | 40 | | private const string privacyNoticeVersionProperty = Namespace + "/PrivacyNoticeVersion"; |
| | | 41 | | private const string duplexClientLocalAddressProperty = Namespace + "/DuplexClientLocalAddress"; |
| | | 42 | | private const string endpointFilterTableProperty = Namespace + "/EndpointFilterTable"; |
| | | 43 | | private const string channelParametersCollectionProperty = Namespace + "/ChannelParametersCollection"; |
| | | 44 | | private const string extendedProtectionPolicy = Namespace + "/ExtendedProtectionPolicy"; |
| | | 45 | | private const bool defaultSupportSecurityContextCancellation = false; |
| | | 46 | | |
| | | 47 | | protected ServiceModelSecurityTokenRequirement() |
| | 99 | 48 | | : base() |
| | | 49 | | { |
| | 99 | 50 | | Properties[SupportSecurityContextCancellationProperty] = defaultSupportSecurityContextCancellation; |
| | 99 | 51 | | } |
| | | 52 | | |
| | 100 | 53 | | public static string SecurityAlgorithmSuiteProperty { get { return securityAlgorithmSuiteProperty; } } |
| | 100 | 54 | | public static string SecurityBindingElementProperty { get { return securityBindingElementProperty; } } |
| | 2 | 55 | | public static string IssuerAddressProperty { get { return issuerAddressProperty; } } |
| | 0 | 56 | | public static string IssuerBindingProperty { get { return issuerBindingProperty; } } |
| | 44 | 57 | | public static string SecureConversationSecurityBindingElementProperty { get { return secureConversationSecurityB |
| | 167 | 58 | | public static string SupportSecurityContextCancellationProperty { get { return supportSecurityContextCancellatio |
| | 100 | 59 | | public static string MessageSecurityVersionProperty { get { return messageSecurityVersionProperty; } } |
| | 2 | 60 | | internal static string DefaultMessageSecurityVersionProperty { get { return defaultMessageSecurityVersionPropert |
| | 46 | 61 | | public static string IssuerBindingContextProperty { get { return issuerBindingContextProperty; } } |
| | 22 | 62 | | public static string TransportSchemeProperty { get { return transportSchemeProperty; } } |
| | 99 | 63 | | public static string IsInitiatorProperty { get { return isInitiatorProperty; } } |
| | 0 | 64 | | public static string TargetAddressProperty { get { return targetAddressProperty; } } |
| | 0 | 65 | | public static string ViaProperty { get { return viaProperty; } } |
| | 122 | 66 | | public static string ListenUriProperty { get { return listenUriProperty; } } |
| | 0 | 67 | | public static string AuditLogLocationProperty { get { return auditLogLocationProperty; } } |
| | 0 | 68 | | public static string SuppressAuditFailureProperty { get { return suppressAuditFailureProperty; } } |
| | 0 | 69 | | public static string MessageAuthenticationAuditLevelProperty { get { return messageAuthenticationAuditLevelPrope |
| | 0 | 70 | | public static string IsOutOfBandTokenProperty { get { return isOutOfBandTokenProperty; } } |
| | 0 | 71 | | public static string PreferSslCertificateAuthenticatorProperty { get { return preferSslCertificateAuthenticatorP |
| | | 72 | | |
| | 55 | 73 | | public static string SupportingTokenAttachmentModeProperty { get { return supportingTokenAttachmentModeProperty; |
| | 77 | 74 | | public static string MessageDirectionProperty { get { return messageDirectionProperty; } } |
| | 12 | 75 | | public static string HttpAuthenticationSchemeProperty { get { return httpAuthenticationSchemeProperty; } } |
| | 48 | 76 | | public static string IssuedSecurityTokenParametersProperty { get { return issuedSecurityTokenParametersProperty; |
| | 0 | 77 | | public static string PrivacyNoticeUriProperty { get { return privacyNoticeUriProperty; } } |
| | 0 | 78 | | public static string PrivacyNoticeVersionProperty { get { return privacyNoticeVersionProperty; } } |
| | 0 | 79 | | public static string DuplexClientLocalAddressProperty { get { return duplexClientLocalAddressProperty; } } |
| | 22 | 80 | | public static string EndpointFilterTableProperty { get { return endpointFilterTableProperty; } } |
| | 0 | 81 | | public static string ChannelParametersCollectionProperty { get { return channelParametersCollectionProperty; } } |
| | 111 | 82 | | public static string ExtendedProtectionPolicy { get { return extendedProtectionPolicy; } } |
| | | 83 | | |
| | | 84 | | public bool IsInitiator |
| | | 85 | | { |
| | | 86 | | get |
| | | 87 | | { |
| | 0 | 88 | | return GetPropertyOrDefault<bool>(IsInitiatorProperty, false); |
| | | 89 | | } |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | public SecurityAlgorithmSuite SecurityAlgorithmSuite |
| | | 93 | | { |
| | | 94 | | get |
| | | 95 | | { |
| | 23 | 96 | | return GetPropertyOrDefault<SecurityAlgorithmSuite>(SecurityAlgorithmSuiteProperty, null); |
| | | 97 | | } |
| | | 98 | | set |
| | | 99 | | { |
| | 77 | 100 | | Properties[SecurityAlgorithmSuiteProperty] = value; |
| | 77 | 101 | | } |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | public SecurityBindingElement SecurityBindingElement |
| | | 105 | | { |
| | | 106 | | get |
| | | 107 | | { |
| | 23 | 108 | | return GetPropertyOrDefault<SecurityBindingElement>(SecurityBindingElementProperty, null); |
| | | 109 | | } |
| | | 110 | | set |
| | | 111 | | { |
| | 77 | 112 | | Properties[SecurityBindingElementProperty] = value; |
| | 77 | 113 | | } |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | public EndpointAddress IssuerAddress |
| | | 117 | | { |
| | | 118 | | get |
| | | 119 | | { |
| | 0 | 120 | | return GetPropertyOrDefault<EndpointAddress>(IssuerAddressProperty, null); |
| | | 121 | | } |
| | | 122 | | set |
| | | 123 | | { |
| | 0 | 124 | | Properties[IssuerAddressProperty] = value; |
| | 0 | 125 | | } |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | public Binding IssuerBinding |
| | | 129 | | { |
| | | 130 | | get |
| | | 131 | | { |
| | 0 | 132 | | return GetPropertyOrDefault<Binding>(IssuerBindingProperty, null); |
| | | 133 | | } |
| | | 134 | | set |
| | | 135 | | { |
| | 0 | 136 | | Properties[IssuerBindingProperty] = value; |
| | 0 | 137 | | } |
| | | 138 | | } |
| | | 139 | | |
| | | 140 | | public SecurityBindingElement SecureConversationSecurityBindingElement |
| | | 141 | | { |
| | | 142 | | get |
| | | 143 | | { |
| | 22 | 144 | | return GetPropertyOrDefault<SecurityBindingElement>(SecureConversationSecurityBindingElementProperty, nu |
| | | 145 | | } |
| | | 146 | | set |
| | | 147 | | { |
| | 0 | 148 | | Properties[SecureConversationSecurityBindingElementProperty] = value; |
| | 0 | 149 | | } |
| | | 150 | | } |
| | | 151 | | |
| | | 152 | | public SecurityTokenVersion MessageSecurityVersion |
| | | 153 | | { |
| | | 154 | | get |
| | | 155 | | { |
| | 0 | 156 | | return GetPropertyOrDefault<SecurityTokenVersion>(MessageSecurityVersionProperty, null); |
| | | 157 | | } |
| | | 158 | | set |
| | | 159 | | { |
| | 77 | 160 | | Properties[MessageSecurityVersionProperty] = value; |
| | 77 | 161 | | } |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | internal MessageSecurityVersion DefaultMessageSecurityVersion |
| | | 165 | | { |
| | | 166 | | get |
| | | 167 | | { |
| | 0 | 168 | | return (TryGetProperty<MessageSecurityVersion>(DefaultMessageSecurityVersionProperty, out MessageSecurit |
| | | 169 | | } |
| | | 170 | | set |
| | | 171 | | { |
| | 2 | 172 | | Properties[DefaultMessageSecurityVersionProperty] = (object)value; |
| | 2 | 173 | | } |
| | | 174 | | } |
| | | 175 | | |
| | | 176 | | public string TransportScheme |
| | | 177 | | { |
| | | 178 | | get |
| | | 179 | | { |
| | 0 | 180 | | return GetPropertyOrDefault<string>(TransportSchemeProperty, null); |
| | | 181 | | } |
| | | 182 | | set |
| | | 183 | | { |
| | 22 | 184 | | Properties[TransportSchemeProperty] = value; |
| | 22 | 185 | | } |
| | | 186 | | } |
| | | 187 | | |
| | | 188 | | internal bool SupportSecurityContextCancellation |
| | | 189 | | { |
| | | 190 | | get |
| | | 191 | | { |
| | 23 | 192 | | return GetPropertyOrDefault<bool>(SupportSecurityContextCancellationProperty, defaultSupportSecurityCont |
| | | 193 | | } |
| | | 194 | | set |
| | | 195 | | { |
| | 22 | 196 | | Properties[SupportSecurityContextCancellationProperty] = value; |
| | 22 | 197 | | } |
| | | 198 | | } |
| | | 199 | | |
| | | 200 | | internal EndpointAddress DuplexClientLocalAddress |
| | | 201 | | { |
| | | 202 | | get |
| | | 203 | | { |
| | 0 | 204 | | return GetPropertyOrDefault<EndpointAddress>(duplexClientLocalAddressProperty, null); |
| | | 205 | | } |
| | | 206 | | set |
| | | 207 | | { |
| | 0 | 208 | | Properties[duplexClientLocalAddressProperty] = value; |
| | 0 | 209 | | } |
| | | 210 | | } |
| | | 211 | | |
| | | 212 | | internal TValue GetPropertyOrDefault<TValue>(string propertyName, TValue defaultValue) |
| | | 213 | | { |
| | 136 | 214 | | if (!TryGetProperty<TValue>(propertyName, out TValue result)) |
| | | 215 | | { |
| | 22 | 216 | | result = defaultValue; |
| | | 217 | | } |
| | 136 | 218 | | return result; |
| | | 219 | | } |
| | | 220 | | |
| | | 221 | | internal string InternalToString() |
| | | 222 | | { |
| | 0 | 223 | | StringBuilder sb = new StringBuilder(); |
| | | 224 | | |
| | 0 | 225 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}:", GetType().ToString())); |
| | 0 | 226 | | foreach (string propertyName in Properties.Keys) |
| | | 227 | | { |
| | 0 | 228 | | object propertyValue = Properties[propertyName]; |
| | 0 | 229 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "PropertyName: {0}", propertyName)); |
| | 0 | 230 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "PropertyValue: {0}", propertyValue)); |
| | 0 | 231 | | sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "---")); |
| | | 232 | | } |
| | 0 | 233 | | return sb.ToString().Trim(); |
| | | 234 | | } |
| | | 235 | | } |
| | | 236 | | } |