| | | 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.Net.Security; |
| | | 5 | | using System.Security.Principal; |
| | | 6 | | using System.Xml; |
| | | 7 | | using CoreWCF.Description; |
| | | 8 | | using CoreWCF.Security; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Channels |
| | | 11 | | { |
| | | 12 | | public class WindowsStreamSecurityBindingElement : StreamUpgradeBindingElement, ITransportTokenAssertionProvider, IP |
| | | 13 | | { |
| | | 14 | | private ProtectionLevel _protectionLevel; |
| | | 15 | | |
| | | 16 | | public WindowsStreamSecurityBindingElement() |
| | 156 | 17 | | : base() |
| | | 18 | | { |
| | 156 | 19 | | _protectionLevel = ConnectionOrientedTransportDefaults.ProtectionLevel; |
| | 156 | 20 | | } |
| | | 21 | | |
| | | 22 | | protected WindowsStreamSecurityBindingElement(WindowsStreamSecurityBindingElement elementToBeCloned) |
| | 192 | 23 | | : base(elementToBeCloned) |
| | | 24 | | { |
| | 192 | 25 | | _protectionLevel = elementToBeCloned._protectionLevel; |
| | 192 | 26 | | } |
| | | 27 | | |
| | | 28 | | public ProtectionLevel ProtectionLevel |
| | | 29 | | { |
| | | 30 | | get |
| | | 31 | | { |
| | 12 | 32 | | return _protectionLevel; |
| | | 33 | | } |
| | | 34 | | set |
| | | 35 | | { |
| | 156 | 36 | | ProtectionLevelHelper.Validate(value); |
| | 156 | 37 | | _protectionLevel = value; |
| | 156 | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public override BindingElement Clone() |
| | | 42 | | { |
| | 192 | 43 | | return new WindowsStreamSecurityBindingElement(this); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public override StreamUpgradeProvider BuildServerStreamUpgradeProvider(BindingContext context) |
| | | 47 | | { |
| | 12 | 48 | | return new WindowsStreamSecurityUpgradeProvider(this, context); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public override T GetProperty<T>(BindingContext context) |
| | | 52 | | { |
| | 36 | 53 | | if (context == null) |
| | | 54 | | { |
| | 0 | 55 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 56 | | } |
| | 36 | 57 | | if (typeof(T) == typeof(ISecurityCapabilities)) |
| | | 58 | | { |
| | 12 | 59 | | return (T)(object)new SecurityCapabilities(true, true, true, _protectionLevel, _protectionLevel); |
| | | 60 | | } |
| | 24 | 61 | | else if (typeof(T) == typeof(IdentityVerifier)) |
| | | 62 | | { |
| | 0 | 63 | | return (T)(object)IdentityVerifier.CreateDefault(); |
| | | 64 | | } |
| | | 65 | | else |
| | | 66 | | { |
| | 24 | 67 | | return context.GetInnerProperty<T>(); |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | #region ITransportTokenAssertionProvider Members |
| | | 72 | | |
| | | 73 | | public XmlElement GetTransportTokenAssertion() |
| | | 74 | | { |
| | 0 | 75 | | XmlDocument document = new XmlDocument(); |
| | 0 | 76 | | XmlElement assertion = |
| | 0 | 77 | | document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix, |
| | 0 | 78 | | TransportPolicyConstants.WindowsTransportSecurityName, |
| | 0 | 79 | | TransportPolicyConstants.DotNetFramingNamespace); |
| | 0 | 80 | | XmlElement protectionLevelElement = document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix, |
| | 0 | 81 | | TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace); |
| | 0 | 82 | | protectionLevelElement.AppendChild(document.CreateTextNode(this.ProtectionLevel.ToString())); |
| | 0 | 83 | | assertion.AppendChild(protectionLevelElement); |
| | 0 | 84 | | return assertion; |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | #endregion |
| | | 88 | | |
| | | 89 | | void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) |
| | | 90 | | { |
| | 0 | 91 | | if (exporter == null) |
| | | 92 | | { |
| | 0 | 93 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter)); |
| | | 94 | | } |
| | | 95 | | |
| | 0 | 96 | | if (context == null) |
| | | 97 | | { |
| | 0 | 98 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 99 | | } |
| | | 100 | | |
| | 0 | 101 | | SecurityBindingElement.ExportPolicyForTransportTokenAssertionProviders(exporter, context); |
| | 0 | 102 | | } |
| | | 103 | | } |
| | | 104 | | } |