| | | 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.Xml; |
| | | 7 | | using CoreWCF.IdentityModel; |
| | | 8 | | using CoreWCF.IdentityModel.Selectors; |
| | | 9 | | using CoreWCF.IdentityModel.Tokens; |
| | | 10 | | using CoreWCF.Runtime; |
| | | 11 | | using CoreWCF.Security.Tokens; |
| | | 12 | | |
| | | 13 | | namespace CoreWCF.Security |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// This class derives from CoreWCF.Security.WSSecurityTokenSerializer and wraps a collection of SecurityTokenHandle |
| | | 17 | | /// Any call to this serilaizer is delegated to the token handler and delegated to the base class if no token handle |
| | | 18 | | /// is registered to handle this particular token or KeyIdentifier. |
| | | 19 | | /// </summary> |
| | | 20 | | internal class WsSecurityTokenSerializerAdapter : WSSecurityTokenSerializer |
| | | 21 | | { |
| | | 22 | | private SecureConversationVersion _scVersion; |
| | | 23 | | private SecurityTokenHandlerCollection _securityTokenHandlers; |
| | | 24 | | private bool _mapExceptionsToSoapFaults; |
| | 2 | 25 | | private ExceptionMapper _exceptionMapper = new ExceptionMapper(); |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Initializes an instance of <see cref="WsSecurityTokenSerializerAdapter"/> |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="securityTokenHandlerCollection"> |
| | | 31 | | /// The <see cref="SecurityTokenHandlerCollection" /> containing the set of <see cref="SecurityTokenHandler" /> |
| | | 32 | | /// objects used for serializing and validating tokens found in WS-Trust messages. |
| | | 33 | | /// </param> |
| | | 34 | | public WsSecurityTokenSerializerAdapter(SecurityTokenHandlerCollection securityTokenHandlerCollection) |
| | 0 | 35 | | : this(securityTokenHandlerCollection, MessageSecurityVersion.Default.SecurityVersion) |
| | | 36 | | { |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Initializes an instance of <see cref="WsSecurityTokenSerializerAdapter"/> |
| | | 41 | | /// </summary> |
| | | 42 | | /// <param name="securityTokenHandlerCollection"> |
| | | 43 | | /// The <see cref="SecurityTokenHandlerCollection" /> containing the set of <see cref="SecurityTokenHandler" /> |
| | | 44 | | /// objects used for serializing and validating tokens found in WS-Trust messages. |
| | | 45 | | /// </param> |
| | | 46 | | /// <param name="securityVersion">The SecurityTokenVersion of the base WSSecurityTokenSerializer.</param> |
| | | 47 | | public WsSecurityTokenSerializerAdapter(SecurityTokenHandlerCollection securityTokenHandlerCollection, SecurityV |
| | 0 | 48 | | : this(securityTokenHandlerCollection, securityVersion, true, new SamlSerializer(), null, null) |
| | | 49 | | { |
| | 0 | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Initializes an instance of <see cref="WsSecurityTokenSerializerAdapter"/> |
| | | 54 | | /// </summary> |
| | | 55 | | /// <param name="securityTokenHandlerCollection"> |
| | | 56 | | /// The <see cref="SecurityTokenHandlerCollection" /> containing the set of <see cref="SecurityTokenHandler" /> |
| | | 57 | | /// objects used for serializing and validating tokens found in WS-Trust messages. |
| | | 58 | | /// </param> |
| | | 59 | | /// <param name="securityVersion">The SecurityVersion of the base WSSecurityTokenSerializer.</param> |
| | | 60 | | /// <param name="emitBspAttributes">Flag that determines if the serailization shoudl be BSP compliant.</param> |
| | | 61 | | /// <param name="samlSerializer">Serializer for SAML 1.1 tokens.</param> |
| | | 62 | | /// <param name="stateEncoder">SecurityStateEncoder used for resolving SCT.</param> |
| | | 63 | | /// <param name="knownTypes">The collection of known claim types.</param> |
| | | 64 | | public WsSecurityTokenSerializerAdapter(SecurityTokenHandlerCollection securityTokenHandlerCollection, SecurityV |
| | 0 | 65 | | : this(securityTokenHandlerCollection, securityVersion, TrustVersion.WSTrust13, SecureConversationVersion.WS |
| | | 66 | | { |
| | 0 | 67 | | } |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Initializes an instance of <see cref="WsSecurityTokenSerializerAdapter"/> |
| | | 71 | | /// </summary> |
| | | 72 | | /// <param name="securityTokenHandlerCollection"> |
| | | 73 | | /// The <see cref="SecurityTokenHandlerCollection" /> containing the set of <see cref="SecurityTokenHandler" /> |
| | | 74 | | /// objects used for serializing and validating tokens found in WS-Trust messages. |
| | | 75 | | /// </param> |
| | | 76 | | /// <param name="securityVersion">The SecurityVersion of the base WSSecurityTokenSerializer.</param> |
| | | 77 | | /// <param name="trustVersion">The TrustVersion of the serializer uses.</param> |
| | | 78 | | /// <param name="secureConversationVersion">The SecureConversationVersion of the serializer.</param> |
| | | 79 | | /// <param name="emitBspAttributes">Flag that determines if the serailization shoudl be BSP compliant.</param> |
| | | 80 | | /// <param name="samlSerializer">Serializer for SAML 1.1 tokens.</param> |
| | | 81 | | /// <param name="stateEncoder">SecurityStateEncoder used for resolving SCT.</param> |
| | | 82 | | /// <param name="knownTypes">The collection of known claim types.</param> |
| | | 83 | | public WsSecurityTokenSerializerAdapter(SecurityTokenHandlerCollection securityTokenHandlerCollection, SecurityV |
| | 2 | 84 | | : base(securityVersion, trustVersion, secureConversationVersion, emitBspAttributes, samlSerializer, stateEnc |
| | | 85 | | { |
| | 2 | 86 | | if (securityTokenHandlerCollection == null) |
| | | 87 | | { |
| | 0 | 88 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(securityTokenHandlerCollection)) |
| | | 89 | | } |
| | | 90 | | |
| | 2 | 91 | | _scVersion = secureConversationVersion; |
| | 2 | 92 | | _securityTokenHandlers = securityTokenHandlerCollection; |
| | 2 | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// Gets and Sets the property that describes if exceptions |
| | | 97 | | /// should be mapped to SOAP Fault exceptions. Default is false. |
| | | 98 | | /// </summary> |
| | | 99 | | public bool MapExceptionsToSoapFaults |
| | | 100 | | { |
| | | 101 | | get |
| | | 102 | | { |
| | 6 | 103 | | return _mapExceptionsToSoapFaults; |
| | | 104 | | } |
| | | 105 | | set |
| | | 106 | | { |
| | 2 | 107 | | _mapExceptionsToSoapFaults = value; |
| | 2 | 108 | | } |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | /// <summary> |
| | | 112 | | /// Gets the SecurityTokenHandlerCollection. |
| | | 113 | | /// </summary> |
| | | 114 | | public SecurityTokenHandlerCollection SecurityTokenHandlers |
| | | 115 | | { |
| | | 116 | | get |
| | | 117 | | { |
| | 0 | 118 | | return _securityTokenHandlers; |
| | | 119 | | } |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | /// <summary> |
| | | 123 | | /// Gets or sets the ExceptionMapper to be used when throwing exceptions. |
| | | 124 | | /// </summary> |
| | | 125 | | public ExceptionMapper ExceptionMapper |
| | | 126 | | { |
| | | 127 | | get |
| | | 128 | | { |
| | 0 | 129 | | return _exceptionMapper; |
| | | 130 | | } |
| | | 131 | | set |
| | | 132 | | { |
| | 2 | 133 | | if (value == null) |
| | | 134 | | { |
| | 0 | 135 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 136 | | } |
| | 2 | 137 | | _exceptionMapper = value; |
| | 2 | 138 | | } |
| | | 139 | | } |
| | | 140 | | |
| | | 141 | | /// <summary> |
| | | 142 | | /// Checks if one of the wrapped SecurityTokenHandlers or the base WSSecurityTokenSerializer |
| | | 143 | | /// can read the security token. |
| | | 144 | | /// </summary> |
| | | 145 | | /// <param name=nameof(reader)>Reader to a Security token.</param> |
| | | 146 | | /// <returns>'True' if the serializer can read the given Security Token.</returns> |
| | | 147 | | /// <exception cref="ArgumentNullException">The input parameter 'reader' is null.</exception> |
| | | 148 | | protected override bool CanReadTokenCore(XmlReader reader) |
| | | 149 | | { |
| | 0 | 150 | | if (reader == null) |
| | | 151 | | { |
| | 0 | 152 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 153 | | } |
| | | 154 | | |
| | 0 | 155 | | if (_securityTokenHandlers.CanReadToken(reader)) |
| | | 156 | | { |
| | 0 | 157 | | return true; |
| | | 158 | | } |
| | | 159 | | |
| | 0 | 160 | | return base.CanReadTokenCore(reader); |
| | | 161 | | } |
| | | 162 | | |
| | | 163 | | /// <summary> |
| | | 164 | | /// Checks if one of the wrapped SecurityTokenHandlers or the base WSSecurityTokenSerializer |
| | | 165 | | /// can write the given security token. |
| | | 166 | | /// </summary> |
| | | 167 | | /// <param name=(nameof(token)>SecurityToken instance.</param> |
| | | 168 | | /// <returns>'True' if the serializer can write the given security token.</returns> |
| | | 169 | | /// <exception cref="ArgumentNullException">The input parameter 'token' is null.</exception> |
| | | 170 | | protected override bool CanWriteTokenCore(SecurityToken token) |
| | | 171 | | { |
| | 0 | 172 | | if (token == null) |
| | | 173 | | { |
| | 0 | 174 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull((nameof(token))); |
| | | 175 | | } |
| | | 176 | | |
| | 0 | 177 | | if (_securityTokenHandlers.CanWriteToken(token)) |
| | | 178 | | { |
| | 0 | 179 | | return true; |
| | | 180 | | } |
| | | 181 | | |
| | 0 | 182 | | return base.CanWriteTokenCore(token); |
| | | 183 | | } |
| | | 184 | | |
| | | 185 | | /// <summary> |
| | | 186 | | /// Deserializes the SecurityToken from the given XmlReader. |
| | | 187 | | /// </summary> |
| | | 188 | | /// <param name=nameof(reader)>Reader to a Security token.</param> |
| | | 189 | | /// <param name="tokenResolver">Instance of SecurityTokenResolver.</param> |
| | | 190 | | /// <returns>'True' if the serializer can read the given Security Token.</returns> |
| | | 191 | | /// <exception cref="ArgumentNullException">The input parameter 'reader' is null.</exception> |
| | | 192 | | protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver) |
| | | 193 | | { |
| | 53 | 194 | | if (reader == null) |
| | | 195 | | { |
| | 0 | 196 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 197 | | } |
| | | 198 | | |
| | | 199 | | try |
| | | 200 | | { |
| | 161 | 201 | | foreach (SecurityTokenHandler securityTokenHandler in _securityTokenHandlers) |
| | | 202 | | { |
| | 54 | 203 | | if (securityTokenHandler.CanReadToken(reader)) |
| | | 204 | | { |
| | 53 | 205 | | SecurityToken token = securityTokenHandler.ReadToken(reader, tokenResolver); |
| | 47 | 206 | | SessionSecurityToken sessionToken = token as SessionSecurityToken; |
| | | 207 | | |
| | 47 | 208 | | if (sessionToken != null) |
| | | 209 | | { |
| | 0 | 210 | | if (sessionToken.SecureConversationVersion.AbsoluteUri != _scVersion.Namespace.Value) |
| | | 211 | | { |
| | 0 | 212 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperInvalidOperation(SR.Format(SR.ID4053 |
| | | 213 | | } |
| | | 214 | | |
| | 0 | 215 | | return SecurityContextSecurityTokenHelper.ConvertSessionTokenToSecurityContextSecurityToken( |
| | | 216 | | } |
| | | 217 | | else |
| | | 218 | | { |
| | 47 | 219 | | return token; |
| | | 220 | | } |
| | | 221 | | } |
| | | 222 | | } |
| | | 223 | | |
| | 0 | 224 | | return base.ReadTokenCore(reader, tokenResolver); |
| | | 225 | | } |
| | 6 | 226 | | catch (Exception ex) |
| | | 227 | | { |
| | 6 | 228 | | if (!(MapExceptionsToSoapFaults && _exceptionMapper.HandleSecurityTokenProcessingException(ex))) |
| | | 229 | | { |
| | 6 | 230 | | throw; |
| | | 231 | | } |
| | | 232 | | Fx.Assert(false, "ExceptionMapper did not handle an exception correctly."); |
| | | 233 | | // This should never happen. ExceptionMapper will handle the exception, in which case, |
| | | 234 | | // a fault exception is thrown or the original exception gets thrown. |
| | 0 | 235 | | } |
| | | 236 | | |
| | 0 | 237 | | return null; |
| | 47 | 238 | | } |
| | | 239 | | |
| | | 240 | | /// <summary> |
| | | 241 | | /// Serializes the SecurityToken to the XmlWriter. |
| | | 242 | | /// </summary> |
| | | 243 | | /// <param name=nameof(writer)>XmlWriter to write to.</param> |
| | | 244 | | /// <param name=(nameof(token)>The SecurityToken to serializer.</param> |
| | | 245 | | /// <exception cref="ArgumentNullException">The input parameter 'writer' or 'token' is null.</exception> |
| | | 246 | | protected override void WriteTokenCore(XmlWriter writer, SecurityToken token) |
| | | 247 | | { |
| | 0 | 248 | | if (writer == null) |
| | | 249 | | { |
| | 0 | 250 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer)); |
| | | 251 | | } |
| | | 252 | | |
| | 0 | 253 | | if (token == null) |
| | | 254 | | { |
| | 0 | 255 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull((nameof(token))); |
| | | 256 | | } |
| | | 257 | | |
| | | 258 | | try |
| | | 259 | | { |
| | | 260 | | // |
| | | 261 | | // Wire the session handler for SCT |
| | | 262 | | // |
| | 0 | 263 | | SecurityContextSecurityToken sct = token as SecurityContextSecurityToken; |
| | 0 | 264 | | if (sct != null) |
| | | 265 | | { |
| | | 266 | | // |
| | | 267 | | // Bare SCT tokens are wrapped with a SessionSecurityToken. |
| | | 268 | | // The property SessionSecurityToken.IsSecurityContextSecurityTokenWrapper will be true. |
| | | 269 | | // |
| | 0 | 270 | | token = SecurityContextSecurityTokenHelper.ConvertSctToSessionToken(sct, _scVersion); |
| | | 271 | | } |
| | | 272 | | |
| | 0 | 273 | | SecurityTokenHandler securityTokenHandler = _securityTokenHandlers[token]; |
| | | 274 | | |
| | 0 | 275 | | if ((securityTokenHandler != null) && (securityTokenHandler.CanWriteToken)) |
| | | 276 | | { |
| | 0 | 277 | | securityTokenHandler.WriteToken(writer, token); |
| | | 278 | | |
| | 0 | 279 | | return; |
| | | 280 | | } |
| | | 281 | | |
| | 0 | 282 | | base.WriteTokenCore(writer, token); |
| | 0 | 283 | | } |
| | 0 | 284 | | catch (Exception ex) |
| | | 285 | | { |
| | 0 | 286 | | if (!(MapExceptionsToSoapFaults && _exceptionMapper.HandleSecurityTokenProcessingException(ex))) |
| | | 287 | | { |
| | 0 | 288 | | throw; |
| | | 289 | | } |
| | | 290 | | Fx.Assert(false, "ExceptionMapper did not handle an exception correctly."); |
| | | 291 | | // This should never happen. ExceptionMapper will handle the exception, in which case, |
| | | 292 | | // a fault exception is thrown or the original exception gets thrown. |
| | 0 | 293 | | } |
| | 0 | 294 | | } |
| | | 295 | | |
| | | 296 | | /// <summary> |
| | | 297 | | /// Checks if one of the wrapped SecurityTokenHandlers or the base WSSecurityTokenSerializer |
| | | 298 | | /// can read the security key identifier. |
| | | 299 | | /// </summary> |
| | | 300 | | /// <param name=nameof(reader)>Reader pointing at a Security Key Identifier {ds:Keyinfo}.</param> |
| | | 301 | | /// <returns>'True' if the serializer can read the given Security Key Identifier.</returns> |
| | | 302 | | /// <exception cref="ArgumentNullException">The <paramref name=nameof(reader)/> is null.</exception> |
| | | 303 | | protected override bool CanReadKeyIdentifierCore(XmlReader reader) |
| | | 304 | | { |
| | 0 | 305 | | if (reader == null) |
| | | 306 | | { |
| | 0 | 307 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 308 | | } |
| | | 309 | | |
| | 0 | 310 | | if (reader.IsStartElement(XmlSignatureConstants.Elements.KeyInfo, XmlSignatureConstants.Namespace)) |
| | | 311 | | { |
| | 0 | 312 | | return true; |
| | | 313 | | } |
| | | 314 | | else |
| | | 315 | | { |
| | 0 | 316 | | return base.CanReadKeyIdentifierCore(reader); |
| | | 317 | | } |
| | | 318 | | } |
| | | 319 | | |
| | | 320 | | /// <summary> |
| | | 321 | | /// Reads an SecurityKeyIdentifier from a XML stream. |
| | | 322 | | /// </summary> |
| | | 323 | | /// <param name=nameof(reader)>An XML reader positioned at an SecurityKeyIdentifier (ds: KeyInfo) as defined in |
| | | 324 | | /// <returns>SecurityKeyIdentifier.</returns> |
| | | 325 | | /// <exception cref="ArgumentNullException">The <paramref name=nameof(reader)/> is null.</exception> |
| | | 326 | | /// <exception cref="InvalidOperationException">If the <paramref name=nameof(reader)/> is not positioned at KeyI |
| | | 327 | | protected override SecurityKeyIdentifier ReadKeyIdentifierCore(XmlReader reader) |
| | | 328 | | { |
| | 0 | 329 | | if (reader == null) |
| | | 330 | | { |
| | 0 | 331 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 332 | | } |
| | | 333 | | |
| | 0 | 334 | | if (reader.IsStartElement(XmlSignatureConstants.Elements.KeyInfo, XmlSignatureConstants.Namespace)) |
| | | 335 | | { |
| | 0 | 336 | | KeyInfo keyInfo = new KeyInfo(this); |
| | 0 | 337 | | keyInfo.ReadXml(XmlDictionaryReader.CreateDictionaryReader(reader)); |
| | 0 | 338 | | return keyInfo.KeyIdentifier; |
| | | 339 | | } |
| | | 340 | | else |
| | | 341 | | { |
| | 0 | 342 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml(reader, SR.Format(SR.ID4192)); |
| | | 343 | | } |
| | | 344 | | } |
| | | 345 | | |
| | | 346 | | /// <summary> |
| | | 347 | | /// Checks if the wrapped SecurityTokenHandler or the base WSSecurityTokenSerializer can read the |
| | | 348 | | /// SecurityKeyIdentifierClause. |
| | | 349 | | /// </summary> |
| | | 350 | | /// <param name=nameof(reader)>Reader to a SecurityKeyIdentifierClause.</param> |
| | | 351 | | /// <returns>'True' if the SecurityKeyIdentifierCause can be read.</returns> |
| | | 352 | | /// <exception cref="ArgumentNullException">The input parameter 'reader' is null.</exception> |
| | | 353 | | protected override bool CanReadKeyIdentifierClauseCore(XmlReader reader) |
| | | 354 | | { |
| | 0 | 355 | | if (reader == null) |
| | | 356 | | { |
| | 0 | 357 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 358 | | } |
| | | 359 | | |
| | 0 | 360 | | foreach (SecurityTokenHandler securityTokenHandler in _securityTokenHandlers) |
| | | 361 | | { |
| | 0 | 362 | | if (securityTokenHandler.CanReadKeyIdentifierClause(reader)) |
| | | 363 | | { |
| | 0 | 364 | | return true; |
| | | 365 | | } |
| | | 366 | | } |
| | | 367 | | |
| | 0 | 368 | | return base.CanReadKeyIdentifierClauseCore(reader); |
| | 0 | 369 | | } |
| | | 370 | | |
| | | 371 | | /// <summary> |
| | | 372 | | /// Checks if the wrapped SecurityTokenHandler or the base WSSecurityTokenSerializer can write the |
| | | 373 | | /// given SecurityKeyIdentifierClause. |
| | | 374 | | /// </summary> |
| | | 375 | | /// <param name="keyIdentifierClause">SecurityKeyIdentifierClause to be checked.</param> |
| | | 376 | | /// <returns>'True' if the SecurityTokenKeyIdentifierClause can be written.</returns> |
| | | 377 | | /// <exception cref="ArgumentNullException">The input parameter 'keyIdentifierClause' is null.</exception> |
| | | 378 | | protected override bool CanWriteKeyIdentifierClauseCore(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 379 | | { |
| | 0 | 380 | | if (keyIdentifierClause == null) |
| | | 381 | | { |
| | 0 | 382 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifierClause)); |
| | | 383 | | } |
| | | 384 | | |
| | 0 | 385 | | foreach (SecurityTokenHandler securityTokenHandler in _securityTokenHandlers) |
| | | 386 | | { |
| | 0 | 387 | | if (securityTokenHandler.CanWriteKeyIdentifierClause(keyIdentifierClause)) |
| | | 388 | | { |
| | 0 | 389 | | return true; |
| | | 390 | | } |
| | | 391 | | } |
| | | 392 | | |
| | 0 | 393 | | return base.CanWriteKeyIdentifierClauseCore(keyIdentifierClause); |
| | 0 | 394 | | } |
| | | 395 | | |
| | | 396 | | /// <summary> |
| | | 397 | | /// Deserializes a SecurityKeyIdentifierClause from the given reader. |
| | | 398 | | /// </summary> |
| | | 399 | | /// <param name=nameof(reader)>XmlReader to a SecurityKeyIdentifierClause.</param> |
| | | 400 | | /// <returns>The deserialized SecurityKeyIdentifierClause.</returns> |
| | | 401 | | /// <exception cref="ArgumentNullException">The input parameter 'reader' is null.</exception> |
| | | 402 | | protected override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlReader reader) |
| | | 403 | | { |
| | 0 | 404 | | if (reader == null) |
| | | 405 | | { |
| | 0 | 406 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader)); |
| | | 407 | | } |
| | | 408 | | |
| | | 409 | | try |
| | | 410 | | { |
| | 0 | 411 | | foreach (SecurityTokenHandler securityTokenHandler in _securityTokenHandlers) |
| | | 412 | | { |
| | 0 | 413 | | if (securityTokenHandler.CanReadKeyIdentifierClause(reader)) |
| | | 414 | | { |
| | 0 | 415 | | return securityTokenHandler.ReadKeyIdentifierClause(reader); |
| | | 416 | | } |
| | | 417 | | } |
| | | 418 | | |
| | 0 | 419 | | return base.ReadKeyIdentifierClauseCore(reader); |
| | | 420 | | } |
| | 0 | 421 | | catch (Exception ex) |
| | | 422 | | { |
| | 0 | 423 | | if (!(MapExceptionsToSoapFaults && _exceptionMapper.HandleSecurityTokenProcessingException(ex))) |
| | | 424 | | { |
| | 0 | 425 | | throw; |
| | | 426 | | } |
| | | 427 | | Fx.Assert(false, "ExceptionMapper did not handle an exception correctly."); |
| | | 428 | | // This should never happen. ExceptionMapper will handle the exception, in which case, |
| | | 429 | | // a fault exception is thrown or the original exception gets thrown. |
| | 0 | 430 | | } |
| | | 431 | | |
| | 0 | 432 | | return null; |
| | 0 | 433 | | } |
| | | 434 | | |
| | | 435 | | /// <summary> |
| | | 436 | | /// Serializes the given SecurityKeyIdentifierClause in a XmlWriter. |
| | | 437 | | /// </summary> |
| | | 438 | | /// <param name=nameof(writer)>XmlWriter to write into.</param> |
| | | 439 | | /// <param name="keyIdentifierClause">SecurityKeyIdentifierClause to be written.</param> |
| | | 440 | | /// <exception cref="ArgumentNullException">The input parameter 'writer' or 'keyIdentifierClause' is null.</exce |
| | | 441 | | protected override void WriteKeyIdentifierClauseCore(XmlWriter writer, SecurityKeyIdentifierClause keyIdentifier |
| | | 442 | | { |
| | 0 | 443 | | if (writer == null) |
| | | 444 | | { |
| | 0 | 445 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer)); |
| | | 446 | | } |
| | | 447 | | |
| | 0 | 448 | | if (keyIdentifierClause == null) |
| | | 449 | | { |
| | 0 | 450 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(keyIdentifierClause)); |
| | | 451 | | } |
| | | 452 | | |
| | | 453 | | try |
| | | 454 | | { |
| | 0 | 455 | | foreach (SecurityTokenHandler securityTokenHandler in _securityTokenHandlers) |
| | | 456 | | { |
| | 0 | 457 | | if (securityTokenHandler.CanWriteKeyIdentifierClause(keyIdentifierClause)) |
| | | 458 | | { |
| | 0 | 459 | | securityTokenHandler.WriteKeyIdentifierClause(writer, keyIdentifierClause); |
| | 0 | 460 | | return; |
| | | 461 | | } |
| | | 462 | | } |
| | | 463 | | |
| | 0 | 464 | | base.WriteKeyIdentifierClauseCore(writer, keyIdentifierClause); |
| | 0 | 465 | | } |
| | 0 | 466 | | catch (Exception ex) |
| | | 467 | | { |
| | 0 | 468 | | if (!(MapExceptionsToSoapFaults && _exceptionMapper.HandleSecurityTokenProcessingException(ex))) |
| | | 469 | | { |
| | 0 | 470 | | throw; |
| | | 471 | | } |
| | | 472 | | Fx.Assert(false, "ExceptionMapper did not handle an exception correctly."); |
| | | 473 | | // This should never happen. ExceptionMapper will handle the exception, in which case, |
| | | 474 | | // a fault exception is thrown or the original exception gets thrown. |
| | 0 | 475 | | } |
| | | 476 | | |
| | 0 | 477 | | } |
| | | 478 | | |
| | | 479 | | |
| | | 480 | | } |
| | | 481 | | } |