| | | 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 System.Globalization; |
| | | 8 | | using System.IO; |
| | | 9 | | using System.Runtime.Serialization; |
| | | 10 | | using System.Security.Authentication.ExtendedProtection; |
| | | 11 | | using System.Xml; |
| | | 12 | | using CoreWCF.Channels; |
| | | 13 | | using CoreWCF.Dispatcher; |
| | | 14 | | using CoreWCF.IdentityModel; |
| | | 15 | | using CoreWCF.IdentityModel.Selectors; |
| | | 16 | | using CoreWCF.IdentityModel.Tokens; |
| | | 17 | | using CoreWCF.Security.Tokens; |
| | | 18 | | |
| | | 19 | | namespace CoreWCF.Security |
| | | 20 | | { |
| | | 21 | | internal class RequestSecurityToken : BodyWriter |
| | | 22 | | { |
| | | 23 | | private string _context; |
| | | 24 | | private string _tokenType; |
| | | 25 | | private string _requestType; |
| | | 26 | | private SecurityToken _entropyToken; |
| | | 27 | | private BinaryNegotiation _negotiationData; |
| | | 28 | | private readonly XmlElement _rstXml; |
| | | 29 | | private IList<XmlElement> _requestProperties; |
| | | 30 | | private byte[] _cachedWriteBuffer; |
| | | 31 | | private int _cachedWriteBufferLength; |
| | | 32 | | private int _keySize; |
| | | 33 | | private SecurityKeyIdentifierClause _renewTarget; |
| | | 34 | | private SecurityKeyIdentifierClause _closeTarget; |
| | | 35 | | private OnGetBinaryNegotiationCallback _onGetBinaryNegotiation; |
| | | 36 | | private SecurityStandardsManager _standardsManager; |
| | | 37 | | private object _appliesTo; |
| | | 38 | | private DataContractSerializer _appliesToSerializer; |
| | | 39 | | private Type _appliesToType; |
| | | 40 | | |
| | | 41 | | public RequestSecurityToken() |
| | 0 | 42 | | : this(SecurityStandardsManager.DefaultInstance) |
| | | 43 | | { |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | public RequestSecurityToken(MessageSecurityVersion messageSecurityVersion, SecurityTokenSerializer securityToken |
| | 0 | 47 | | : this(SecurityUtils.CreateSecurityStandardsManager(messageSecurityVersion, securityTokenSerializer)) |
| | | 48 | | { |
| | 0 | 49 | | } |
| | | 50 | | |
| | | 51 | | public RequestSecurityToken(MessageSecurityVersion messageSecurityVersion, |
| | | 52 | | SecurityTokenSerializer securityTokenSerializer, |
| | | 53 | | XmlElement requestSecurityTokenXml, |
| | | 54 | | string context, |
| | | 55 | | string tokenType, |
| | | 56 | | string requestType, |
| | | 57 | | int keySize, |
| | | 58 | | SecurityKeyIdentifierClause renewTarget, |
| | | 59 | | SecurityKeyIdentifierClause closeTarget) |
| | 0 | 60 | | : this(SecurityUtils.CreateSecurityStandardsManager(messageSecurityVersion, securityTokenSerializer), |
| | 0 | 61 | | requestSecurityTokenXml, |
| | 0 | 62 | | context, |
| | 0 | 63 | | tokenType, |
| | 0 | 64 | | requestType, |
| | 0 | 65 | | keySize, |
| | 0 | 66 | | renewTarget, |
| | 0 | 67 | | closeTarget) |
| | | 68 | | { |
| | 0 | 69 | | } |
| | | 70 | | |
| | | 71 | | public RequestSecurityToken(XmlElement requestSecurityTokenXml, |
| | | 72 | | string context, |
| | | 73 | | string tokenType, |
| | | 74 | | string requestType, |
| | | 75 | | int keySize, |
| | | 76 | | SecurityKeyIdentifierClause renewTarget, |
| | | 77 | | SecurityKeyIdentifierClause closeTarget) |
| | 0 | 78 | | : this(SecurityStandardsManager.DefaultInstance, |
| | 0 | 79 | | requestSecurityTokenXml, |
| | 0 | 80 | | context, |
| | 0 | 81 | | tokenType, |
| | 0 | 82 | | requestType, |
| | 0 | 83 | | keySize, |
| | 0 | 84 | | renewTarget, |
| | 0 | 85 | | closeTarget) |
| | | 86 | | { |
| | 0 | 87 | | } |
| | | 88 | | |
| | | 89 | | internal RequestSecurityToken(SecurityStandardsManager standardsManager, |
| | | 90 | | XmlElement rstXml, |
| | | 91 | | string context, |
| | | 92 | | string tokenType, |
| | | 93 | | string requestType, |
| | | 94 | | int keySize, |
| | | 95 | | SecurityKeyIdentifierClause renewTarget, |
| | | 96 | | SecurityKeyIdentifierClause closeTarget) |
| | 20 | 97 | | : base(true) |
| | | 98 | | { |
| | 20 | 99 | | _standardsManager = standardsManager ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Argume |
| | 20 | 100 | | _rstXml = rstXml ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rstXml)); |
| | 20 | 101 | | _context = context; |
| | 20 | 102 | | _tokenType = tokenType; |
| | 20 | 103 | | _keySize = keySize; |
| | 20 | 104 | | _requestType = requestType; |
| | 20 | 105 | | _renewTarget = renewTarget; |
| | 20 | 106 | | _closeTarget = closeTarget; |
| | 20 | 107 | | IsReceiver = true; |
| | 20 | 108 | | IsReadOnly = true; |
| | 20 | 109 | | } |
| | | 110 | | |
| | | 111 | | internal RequestSecurityToken(SecurityStandardsManager standardsManager) |
| | 0 | 112 | | : this(standardsManager, true) |
| | | 113 | | { |
| | | 114 | | // no op |
| | 0 | 115 | | } |
| | | 116 | | |
| | | 117 | | internal RequestSecurityToken(SecurityStandardsManager standardsManager, bool isBuffered) |
| | 0 | 118 | | : base(isBuffered) |
| | | 119 | | { |
| | 0 | 120 | | _standardsManager = standardsManager ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Argume |
| | 0 | 121 | | _requestType = _standardsManager.TrustDriver.RequestTypeIssue; |
| | 0 | 122 | | _requestProperties = null; |
| | 0 | 123 | | IsReceiver = false; |
| | 0 | 124 | | IsReadOnly = false; |
| | 0 | 125 | | } |
| | | 126 | | |
| | | 127 | | public ChannelBinding GetChannelBinding() |
| | | 128 | | { |
| | 0 | 129 | | if (Message == null) |
| | | 130 | | { |
| | 0 | 131 | | return null; |
| | | 132 | | } |
| | | 133 | | |
| | 0 | 134 | | ChannelBindingMessageProperty.TryGet(Message, out ChannelBindingMessageProperty channelBindingMessagePropert |
| | 0 | 135 | | ChannelBinding channelBinding = null; |
| | | 136 | | |
| | 0 | 137 | | if (channelBindingMessageProperty != null) |
| | | 138 | | { |
| | 0 | 139 | | channelBinding = channelBindingMessageProperty.ChannelBinding; |
| | | 140 | | } |
| | | 141 | | |
| | 0 | 142 | | return channelBinding; |
| | | 143 | | } |
| | | 144 | | |
| | | 145 | | /// <summary> |
| | | 146 | | /// Will hold a reference to the outbound message from which we will fish the ChannelBinding out of. |
| | | 147 | | /// </summary> |
| | 0 | 148 | | public Message Message { get; set; } |
| | | 149 | | |
| | | 150 | | public string Context |
| | | 151 | | { |
| | | 152 | | get |
| | | 153 | | { |
| | 20 | 154 | | return _context; |
| | | 155 | | } |
| | | 156 | | set |
| | | 157 | | { |
| | 0 | 158 | | if (IsReadOnly) |
| | | 159 | | { |
| | 0 | 160 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 161 | | } |
| | | 162 | | |
| | 0 | 163 | | _context = value; |
| | 0 | 164 | | } |
| | | 165 | | } |
| | | 166 | | |
| | | 167 | | public string TokenType |
| | | 168 | | { |
| | | 169 | | get |
| | | 170 | | { |
| | 20 | 171 | | return _tokenType; |
| | | 172 | | } |
| | | 173 | | set |
| | | 174 | | { |
| | 0 | 175 | | if (IsReadOnly) |
| | | 176 | | { |
| | 0 | 177 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 178 | | } |
| | | 179 | | |
| | 0 | 180 | | _tokenType = value; |
| | 0 | 181 | | } |
| | | 182 | | } |
| | | 183 | | |
| | | 184 | | public int KeySize |
| | | 185 | | { |
| | | 186 | | get |
| | | 187 | | { |
| | 30 | 188 | | return _keySize; |
| | | 189 | | } |
| | | 190 | | set |
| | | 191 | | { |
| | 0 | 192 | | if (IsReadOnly) |
| | | 193 | | { |
| | 0 | 194 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 195 | | } |
| | | 196 | | |
| | 0 | 197 | | if (value < 0) |
| | | 198 | | { |
| | 0 | 199 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 200 | | } |
| | | 201 | | |
| | 0 | 202 | | _keySize = value; |
| | 0 | 203 | | } |
| | | 204 | | } |
| | | 205 | | |
| | 20 | 206 | | public bool IsReadOnly { get; private set; } |
| | | 207 | | |
| | | 208 | | public delegate void OnGetBinaryNegotiationCallback(ChannelBinding channelBinding); |
| | | 209 | | public OnGetBinaryNegotiationCallback OnGetBinaryNegotiation |
| | | 210 | | { |
| | | 211 | | get |
| | | 212 | | { |
| | 0 | 213 | | return _onGetBinaryNegotiation; |
| | | 214 | | } |
| | | 215 | | set |
| | | 216 | | { |
| | 0 | 217 | | if (IsReadOnly) |
| | | 218 | | { |
| | 0 | 219 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 220 | | } |
| | 0 | 221 | | _onGetBinaryNegotiation = value; |
| | 0 | 222 | | } |
| | | 223 | | } |
| | | 224 | | |
| | | 225 | | public IEnumerable<XmlElement> RequestProperties |
| | | 226 | | { |
| | | 227 | | get |
| | | 228 | | { |
| | 0 | 229 | | if (IsReceiver) |
| | | 230 | | { |
| | 0 | 231 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 232 | | } |
| | 0 | 233 | | return _requestProperties; |
| | | 234 | | } |
| | | 235 | | set |
| | | 236 | | { |
| | 0 | 237 | | if (IsReadOnly) |
| | | 238 | | { |
| | 0 | 239 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 240 | | } |
| | | 241 | | |
| | 0 | 242 | | if (value != null) |
| | | 243 | | { |
| | 0 | 244 | | int index = 0; |
| | 0 | 245 | | Collection<XmlElement> coll = new Collection<XmlElement>(); |
| | 0 | 246 | | foreach (XmlElement property in value) |
| | | 247 | | { |
| | 0 | 248 | | if (property == null) |
| | | 249 | | { |
| | 0 | 250 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(string.F |
| | | 251 | | } |
| | | 252 | | |
| | 0 | 253 | | coll.Add(property); |
| | 0 | 254 | | ++index; |
| | | 255 | | } |
| | 0 | 256 | | _requestProperties = coll; |
| | | 257 | | } |
| | | 258 | | else |
| | | 259 | | { |
| | 0 | 260 | | _requestProperties = null; |
| | | 261 | | } |
| | 0 | 262 | | } |
| | | 263 | | } |
| | | 264 | | |
| | | 265 | | public string RequestType |
| | | 266 | | { |
| | | 267 | | get |
| | | 268 | | { |
| | 40 | 269 | | return _requestType; |
| | | 270 | | } |
| | | 271 | | set |
| | | 272 | | { |
| | 0 | 273 | | if (IsReadOnly) |
| | | 274 | | { |
| | 0 | 275 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 276 | | } |
| | | 277 | | |
| | 0 | 278 | | _requestType = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 0 | 279 | | } |
| | | 280 | | } |
| | | 281 | | |
| | | 282 | | public SecurityKeyIdentifierClause RenewTarget |
| | | 283 | | { |
| | | 284 | | get |
| | | 285 | | { |
| | 0 | 286 | | return _renewTarget; |
| | | 287 | | } |
| | | 288 | | set |
| | | 289 | | { |
| | 0 | 290 | | if (IsReadOnly) |
| | | 291 | | { |
| | 0 | 292 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 293 | | } |
| | | 294 | | |
| | 0 | 295 | | _renewTarget = value; |
| | 0 | 296 | | } |
| | | 297 | | } |
| | | 298 | | |
| | | 299 | | public SecurityKeyIdentifierClause CloseTarget |
| | | 300 | | { |
| | | 301 | | get |
| | | 302 | | { |
| | 20 | 303 | | return _closeTarget; |
| | | 304 | | } |
| | | 305 | | set |
| | | 306 | | { |
| | 0 | 307 | | if (IsReadOnly) |
| | | 308 | | { |
| | 0 | 309 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 310 | | } |
| | | 311 | | |
| | 0 | 312 | | _closeTarget = value; |
| | 0 | 313 | | } |
| | | 314 | | } |
| | | 315 | | |
| | | 316 | | public XmlElement RequestSecurityTokenXml |
| | | 317 | | { |
| | | 318 | | get |
| | | 319 | | { |
| | 20 | 320 | | if (!IsReceiver) |
| | | 321 | | { |
| | 0 | 322 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 323 | | } |
| | 20 | 324 | | return _rstXml; |
| | | 325 | | } |
| | | 326 | | } |
| | | 327 | | |
| | | 328 | | internal SecurityStandardsManager StandardsManager |
| | | 329 | | { |
| | | 330 | | get |
| | | 331 | | { |
| | 0 | 332 | | return _standardsManager; |
| | | 333 | | } |
| | | 334 | | set |
| | | 335 | | { |
| | 0 | 336 | | if (IsReadOnly) |
| | | 337 | | { |
| | 0 | 338 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 339 | | } |
| | | 340 | | |
| | 0 | 341 | | _standardsManager = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullE |
| | 0 | 342 | | } |
| | | 343 | | } |
| | | 344 | | |
| | 40 | 345 | | internal bool IsReceiver { get; } |
| | | 346 | | |
| | | 347 | | internal object AppliesTo |
| | | 348 | | { |
| | | 349 | | get |
| | | 350 | | { |
| | 0 | 351 | | if (IsReceiver) |
| | | 352 | | { |
| | 0 | 353 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 354 | | } |
| | 0 | 355 | | return _appliesTo; |
| | | 356 | | } |
| | | 357 | | } |
| | | 358 | | |
| | | 359 | | internal DataContractSerializer AppliesToSerializer |
| | | 360 | | { |
| | | 361 | | get |
| | | 362 | | { |
| | 0 | 363 | | if (IsReceiver) |
| | | 364 | | { |
| | 0 | 365 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 366 | | } |
| | 0 | 367 | | return _appliesToSerializer; |
| | | 368 | | } |
| | | 369 | | } |
| | | 370 | | |
| | | 371 | | internal Type AppliesToType |
| | | 372 | | { |
| | | 373 | | get |
| | | 374 | | { |
| | 0 | 375 | | if (IsReceiver) |
| | | 376 | | { |
| | 0 | 377 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR |
| | | 378 | | } |
| | 0 | 379 | | return _appliesToType; |
| | | 380 | | } |
| | | 381 | | } |
| | | 382 | | |
| | 20 | 383 | | protected object ThisLock { get; } = new object(); |
| | | 384 | | |
| | | 385 | | internal void SetBinaryNegotiation(BinaryNegotiation negotiation) |
| | | 386 | | { |
| | 0 | 387 | | if (IsReadOnly) |
| | | 388 | | { |
| | 0 | 389 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Obj |
| | | 390 | | } |
| | | 391 | | |
| | 0 | 392 | | _negotiationData = negotiation ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(ne |
| | 0 | 393 | | } |
| | | 394 | | |
| | | 395 | | internal BinaryNegotiation GetBinaryNegotiation() |
| | | 396 | | { |
| | 0 | 397 | | if (IsReceiver) |
| | | 398 | | { |
| | 0 | 399 | | return _standardsManager.TrustDriver.GetBinaryNegotiation(this); |
| | | 400 | | } |
| | 0 | 401 | | else if (_negotiationData == null && _onGetBinaryNegotiation != null) |
| | | 402 | | { |
| | 0 | 403 | | _onGetBinaryNegotiation(GetChannelBinding()); |
| | | 404 | | } |
| | 0 | 405 | | return _negotiationData; |
| | | 406 | | } |
| | | 407 | | |
| | | 408 | | public SecurityToken GetRequestorEntropy() |
| | | 409 | | { |
| | 0 | 410 | | return GetRequestorEntropy(null); |
| | | 411 | | } |
| | | 412 | | |
| | | 413 | | internal SecurityToken GetRequestorEntropy(SecurityTokenResolver resolver) |
| | | 414 | | { |
| | 10 | 415 | | if (IsReceiver) |
| | | 416 | | { |
| | 10 | 417 | | return _standardsManager.TrustDriver.GetEntropy(this, resolver); |
| | | 418 | | } |
| | | 419 | | else |
| | | 420 | | { |
| | 0 | 421 | | return _entropyToken; |
| | | 422 | | } |
| | | 423 | | } |
| | | 424 | | |
| | | 425 | | //public void SetRequestorEntropy(byte[] entropy) |
| | | 426 | | //{ |
| | | 427 | | // if (this.IsReadOnly) |
| | | 428 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.O |
| | | 429 | | // this.entropyToken = (entropy != null) ? new NonceToken(entropy) : null; |
| | | 430 | | //} |
| | | 431 | | |
| | | 432 | | internal void SetRequestorEntropy(WrappedKeySecurityToken entropyToken) |
| | | 433 | | { |
| | 0 | 434 | | if (IsReadOnly) |
| | | 435 | | { |
| | 0 | 436 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Obj |
| | | 437 | | } |
| | | 438 | | |
| | 0 | 439 | | _entropyToken = entropyToken; |
| | 0 | 440 | | } |
| | | 441 | | |
| | | 442 | | public void SetAppliesTo<T>(T appliesTo, DataContractSerializer serializer) |
| | | 443 | | { |
| | 0 | 444 | | if (IsReadOnly) |
| | | 445 | | { |
| | 0 | 446 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Obj |
| | | 447 | | } |
| | | 448 | | |
| | 0 | 449 | | if (appliesTo != null && serializer == null) |
| | | 450 | | { |
| | 0 | 451 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(serializer)); |
| | | 452 | | } |
| | 0 | 453 | | _appliesTo = appliesTo; |
| | 0 | 454 | | _appliesToSerializer = serializer; |
| | 0 | 455 | | _appliesToType = typeof(T); |
| | 0 | 456 | | } |
| | | 457 | | |
| | | 458 | | public void GetAppliesToQName(out string localName, out string namespaceUri) |
| | | 459 | | { |
| | 10 | 460 | | if (!IsReceiver) |
| | | 461 | | { |
| | 0 | 462 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Ite |
| | | 463 | | } |
| | | 464 | | |
| | 10 | 465 | | _standardsManager.TrustDriver.GetAppliesToQName(this, out localName, out namespaceUri); |
| | 10 | 466 | | } |
| | | 467 | | |
| | | 468 | | public T GetAppliesTo<T>() |
| | | 469 | | { |
| | 0 | 470 | | return GetAppliesTo<T>(DataContractSerializerDefaults.CreateSerializer(typeof(T), DataContractSerializerDefa |
| | | 471 | | } |
| | | 472 | | |
| | | 473 | | public T GetAppliesTo<T>(XmlObjectSerializer serializer) |
| | | 474 | | { |
| | 0 | 475 | | if (IsReceiver) |
| | | 476 | | { |
| | 0 | 477 | | if (serializer == null) |
| | | 478 | | { |
| | 0 | 479 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(serializer)); |
| | | 480 | | } |
| | 0 | 481 | | return _standardsManager.TrustDriver.GetAppliesTo<T>(this, serializer); |
| | | 482 | | } |
| | | 483 | | else |
| | | 484 | | { |
| | 0 | 485 | | return (T)_appliesTo; |
| | | 486 | | } |
| | | 487 | | } |
| | | 488 | | |
| | | 489 | | private void OnWriteTo(XmlWriter writer) |
| | | 490 | | { |
| | 0 | 491 | | if (IsReceiver) |
| | | 492 | | { |
| | 0 | 493 | | _rstXml.WriteTo(writer); |
| | | 494 | | } |
| | | 495 | | else |
| | | 496 | | { |
| | 0 | 497 | | _standardsManager.TrustDriver.WriteRequestSecurityToken(this, writer); |
| | | 498 | | } |
| | 0 | 499 | | } |
| | | 500 | | |
| | | 501 | | public void WriteTo(XmlWriter writer) |
| | | 502 | | { |
| | 0 | 503 | | if (writer == null) |
| | | 504 | | { |
| | 0 | 505 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer)); |
| | | 506 | | } |
| | | 507 | | |
| | 0 | 508 | | if (IsReadOnly) |
| | | 509 | | { |
| | | 510 | | // cache the serialized bytes to ensure repeatability |
| | 0 | 511 | | if (_cachedWriteBuffer == null) |
| | | 512 | | { |
| | 0 | 513 | | MemoryStream stream = new MemoryStream(); |
| | 0 | 514 | | using (XmlDictionaryWriter binaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream, XD.Dictiona |
| | | 515 | | { |
| | 0 | 516 | | OnWriteTo(binaryWriter); |
| | 0 | 517 | | binaryWriter.Flush(); |
| | 0 | 518 | | stream.Flush(); |
| | 0 | 519 | | stream.Seek(0, SeekOrigin.Begin); |
| | 0 | 520 | | _cachedWriteBuffer = stream.GetBuffer(); |
| | 0 | 521 | | _cachedWriteBufferLength = (int)stream.Length; |
| | 0 | 522 | | } |
| | | 523 | | } |
| | 0 | 524 | | writer.WriteNode(XmlDictionaryReader.CreateBinaryReader(_cachedWriteBuffer, 0, _cachedWriteBufferLength, |
| | | 525 | | } |
| | | 526 | | else |
| | | 527 | | { |
| | 0 | 528 | | OnWriteTo(writer); |
| | | 529 | | } |
| | 0 | 530 | | } |
| | | 531 | | |
| | | 532 | | public static RequestSecurityToken CreateFrom(XmlReader reader) |
| | | 533 | | { |
| | 0 | 534 | | return CreateFrom(SecurityStandardsManager.DefaultInstance, reader); |
| | | 535 | | } |
| | | 536 | | |
| | | 537 | | public static RequestSecurityToken CreateFrom(XmlReader reader, MessageSecurityVersion messageSecurityVersion, S |
| | | 538 | | { |
| | 0 | 539 | | return CreateFrom(SecurityUtils.CreateSecurityStandardsManager(messageSecurityVersion, securityTokenSerializ |
| | | 540 | | } |
| | | 541 | | |
| | | 542 | | internal static RequestSecurityToken CreateFrom(SecurityStandardsManager standardsManager, XmlReader reader) |
| | | 543 | | { |
| | 0 | 544 | | return standardsManager.TrustDriver.CreateRequestSecurityToken(reader); |
| | | 545 | | } |
| | | 546 | | |
| | | 547 | | public void MakeReadOnly() |
| | | 548 | | { |
| | 0 | 549 | | if (!IsReadOnly) |
| | | 550 | | { |
| | 0 | 551 | | IsReadOnly = true; |
| | 0 | 552 | | if (_requestProperties != null) |
| | | 553 | | { |
| | 0 | 554 | | _requestProperties = new ReadOnlyCollection<XmlElement>(_requestProperties); |
| | | 555 | | } |
| | 0 | 556 | | OnMakeReadOnly(); |
| | | 557 | | } |
| | 0 | 558 | | } |
| | | 559 | | |
| | 0 | 560 | | protected internal virtual void OnWriteCustomAttributes(XmlWriter writer) { } |
| | | 561 | | |
| | 0 | 562 | | protected internal virtual void OnWriteCustomElements(XmlWriter writer) { } |
| | | 563 | | |
| | 0 | 564 | | protected internal virtual void OnMakeReadOnly() { } |
| | | 565 | | |
| | | 566 | | protected override void OnWriteBodyContents(XmlDictionaryWriter writer) |
| | | 567 | | { |
| | 0 | 568 | | WriteTo(writer); |
| | 0 | 569 | | } |
| | | 570 | | } |
| | | 571 | | } |