File: System\ServiceModel\Channels\UnixPosixIdentityBindingElement.cs
Web Access
Project: src\src\System.ServiceModel.UnixDomainSocket\src\System.ServiceModel.UnixDomainSocket.csproj (System.ServiceModel.UnixDomainSocket)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.ComponentModel;
using System.Net.Security;
using System.ServiceModel.Security;
 
namespace System.ServiceModel.Channels
{
    public class UnixPosixIdentityBindingElement : StreamUpgradeBindingElement
    {
 
        public UnixPosixIdentityBindingElement() : base()
        {
        }
 
        protected UnixPosixIdentityBindingElement(UnixPosixIdentityBindingElement elementToBeCloned) : base(elementToBeCloned)
        {
        }
 
        public override BindingElement Clone() => new UnixPosixIdentityBindingElement(this);
 
        public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
            }
 
            context.BindingParameters.Add(this);
            return context.BuildInnerChannelFactory<TChannel>();
        }
 
        public override bool CanBuildChannelFactory<TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
            }
 
            context.BindingParameters.Add(this);
            return context.CanBuildInnerChannelFactory<TChannel>();
        }
 
        public override StreamUpgradeProvider BuildClientStreamUpgradeProvider(BindingContext context) => new UnixPosixIdentitySecurityUpgradeProvider(this, context);
 
        public override T GetProperty<T>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
            }
 
            if (typeof(T) == typeof(ISecurityCapabilities))
            {
                return (T)(object)new SecurityCapabilities(true, true, true, Net.Security.ProtectionLevel.None, Net.Security.ProtectionLevel.None);
            }
            else if (typeof(T) == typeof(IdentityVerifier))
            {
                return (T)(object)IdentityVerifier.CreateDefault();
            }
            else
            {
                return context.GetInnerProperty<T>();
            }
        }
    }
}