| | | 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.Net.Security; |
| | | 6 | | using CoreWCF.Security; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public class UnixPosixIdentityBindingElement : StreamUpgradeBindingElement |
| | | 11 | | { |
| | | 12 | | private ProtectionLevel _protectionLevel; |
| | | 13 | | |
| | | 14 | | public UnixPosixIdentityBindingElement() |
| | 17 | 15 | | : base() |
| | | 16 | | { |
| | 17 | 17 | | _protectionLevel = ConnectionOrientedTransportDefaults.ProtectionLevel; |
| | 17 | 18 | | } |
| | | 19 | | |
| | | 20 | | protected UnixPosixIdentityBindingElement(UnixPosixIdentityBindingElement elementToBeCloned) |
| | 19 | 21 | | : base(elementToBeCloned) |
| | | 22 | | { |
| | 19 | 23 | | _protectionLevel = elementToBeCloned._protectionLevel; |
| | 19 | 24 | | } |
| | | 25 | | |
| | | 26 | | public override BindingElement Clone() |
| | | 27 | | { |
| | 19 | 28 | | return new UnixPosixIdentityBindingElement(this); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public override StreamUpgradeProvider BuildServerStreamUpgradeProvider(BindingContext context) |
| | | 32 | | { |
| | 2 | 33 | | if(string.Compare(context.Binding.Scheme, "net.uds", true) != 0) |
| | | 34 | | { |
| | 0 | 35 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(context.Binding.Scheme), SR.UDSUriSc |
| | | 36 | | } |
| | 2 | 37 | | return new UnixPosixIdentitySecurityUpgradeProvider(this, context); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | public override T GetProperty<T>(BindingContext context) |
| | | 41 | | { |
| | 4 | 42 | | if (context == null) |
| | | 43 | | { |
| | 0 | 44 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 45 | | } |
| | | 46 | | |
| | 4 | 47 | | if (typeof(T) == typeof(ISecurityCapabilities)) |
| | | 48 | | { |
| | 2 | 49 | | return (T)(object)new SecurityCapabilities(true, true, true, _protectionLevel, _protectionLevel); |
| | | 50 | | } |
| | 2 | 51 | | else if (typeof(T) == typeof(IdentityVerifier)) |
| | | 52 | | { |
| | 0 | 53 | | return (T)(object)IdentityVerifier.CreateDefault(); |
| | | 54 | | } |
| | | 55 | | else |
| | | 56 | | { |
| | 2 | 57 | | return context.GetInnerProperty<T>(); |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | } |
| | | 61 | | } |
| | | 62 | | |