public NetMsmqBinding(NetMsmqSecurityMode securityMode)
 {
     if (!NetMsmqSecurityModeHelper.IsDefined(securityMode))
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("mode", (int)securityMode, typeof(NetMsmqSecurityMode)));
     Initialize();
     this.security = new NetMsmqSecurity(securityMode);
 }
Exemplo n.º 2
0
 private static bool IsValidTransport(MsmqTransportBindingElement msmq, out UnifiedSecurityMode mode)
 {
     mode = 0;
     if (msmq == null)
     {
         return(false);
     }
     return(NetMsmqSecurity.IsConfiguredTransportSecurity(msmq, out mode));
 }
Exemplo n.º 3
0
 public NetMsmqBinding(NetMsmqSecurityMode securityMode)
 {
     if (!NetMsmqSecurityModeHelper.IsDefined(securityMode))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("mode", (int)securityMode, typeof(NetMsmqSecurityMode)));
     }
     this.Initialize();
     this.security = new NetMsmqSecurity(securityMode);
 }
 internal void InitializeFrom(NetMsmqSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Mode, security.Mode);
     this.Transport.InitializeFrom(security.Transport);
     this.Message.InitializeFrom(security.Message);
 }
 internal void InitializeFrom(NetMsmqSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     this.Mode = security.Mode;
     this.Transport.InitializeFrom(security.Transport);
     this.Message.InitializeFrom(security.Message);
 }
 internal void ApplyConfiguration(NetMsmqSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     security.Mode = this.Mode;
     this.Transport.ApplyConfiguration(security.Transport);
     this.Message.ApplyConfiguration(security.Message);
 }
        //
        internal static bool TryCreate(SecurityBindingElement sbe, NetMsmqSecurityMode mode, out NetMsmqSecurity security)
        {
            security = null;
            MessageSecurityOverMsmq messageSecurity;

            if (!MessageSecurityOverMsmq.TryCreate(sbe, out messageSecurity))
            {
                messageSecurity = null;
            }
            security = new NetMsmqSecurity(mode, null, messageSecurity);
            return(sbe == null || Config.SecurityElement.AreBindingsMatching(security.CreateMessageSecurity(), sbe, false));
        }
Exemplo n.º 8
0
        private static bool TryCreateSecurity(SecurityBindingElement sbe, UnifiedSecurityMode mode, out NetMsmqSecurity security)
        {
            if (sbe != null)
            {
                mode &= UnifiedSecurityMode.Both | UnifiedSecurityMode.Message;
            }
            else
            {
                mode &= ~(UnifiedSecurityMode.Both | UnifiedSecurityMode.Message);
            }
            NetMsmqSecurityMode mode2 = NetMsmqSecurityModeHelper.ToSecurityMode(mode);

            return(NetMsmqSecurity.TryCreate(sbe, mode2, out security));
        }
 internal static bool TryCreate(SecurityBindingElement sbe, NetMsmqSecurityMode mode, out NetMsmqSecurity security)
 {
     MessageSecurityOverMsmq msmq;
     security = null;
     if (!MessageSecurityOverMsmq.TryCreate(sbe, out msmq))
     {
         msmq = null;
     }
     security = new NetMsmqSecurity(mode, null, msmq);
     if (sbe != null)
     {
         return SecurityElementBase.AreBindingsMatching(security.CreateMessageSecurity(), sbe, false);
     }
     return true;
 }
Exemplo n.º 10
0
        internal static bool TryCreate(SecurityBindingElement sbe, NetMsmqSecurityMode mode, out NetMsmqSecurity security)
        {
            MessageSecurityOverMsmq msmq;

            security = null;
            if (!MessageSecurityOverMsmq.TryCreate(sbe, out msmq))
            {
                msmq = null;
            }
            security = new NetMsmqSecurity(mode, null, msmq);
            if (sbe != null)
            {
                return(SecurityElementBase.AreBindingsMatching(security.CreateMessageSecurity(), sbe, false));
            }
            return(true);
        }
Exemplo n.º 11
0
        private static void GetNetMsmqBindingDetails(NetMsmqBinding binding, ref string name, ref string mode, ref string credentialType)
        {
            name = GetBindingName <NetMsmqBinding>(binding);

            NetMsmqSecurity netMsmqSecurity = binding.Security;

            mode = netMsmqSecurity?.Mode.ToString();
            switch (netMsmqSecurity?.Mode)
            {
            case NetMsmqSecurityMode.None:
                credentialType = "N/A";
                break;

            case NetMsmqSecurityMode.Transport:
            case NetMsmqSecurityMode.Message:
            case NetMsmqSecurityMode.Both:
                credentialType = $"{netMsmqSecurity.Transport?.MsmqAuthenticationMode.ToString()}+{netMsmqSecurity.Message?.ClientCredentialType.ToString()}";
                break;
            }
        }
Exemplo n.º 12
0
        static bool TryCreateSecurity(SecurityBindingElement sbe, UnifiedSecurityMode mode, out NetMsmqSecurity security)
        {
            if (sbe != null)
            {
                mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.Both;
            }
            else
            {
                mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.Both);
            }

            NetMsmqSecurityMode netMsmqSecurityMode = NetMsmqSecurityModeHelper.ToSecurityMode(mode);

            Fx.Assert(NetMsmqSecurityModeHelper.IsDefined(netMsmqSecurityMode), string.Format("Invalid NetMsmqSecurityMode value: {0}.", netMsmqSecurityMode.ToString()));

            if (NetMsmqSecurity.TryCreate(sbe, netMsmqSecurityMode, out security))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 13
0
 private NetMsmqBinding(NetMsmqSecurity security)
 {
     this.Initialize();
     this.security = security;
 }
Exemplo n.º 14
0
 public NetMsmqBinding()
 {
     this.Initialize();
     this.security = new NetMsmqSecurity();
 }
Exemplo n.º 15
0
 NetMsmqBinding(NetMsmqSecurity security)
 {
     Initialize();
     Fx.Assert(security != null, "Invalid (null) NetMsmqSecurity value");
     this.security = security;
 }
 private NetMsmqBinding(NetMsmqSecurity security)
 {
     this.Initialize();
     this.security = security;
 }
 public NetMsmqBinding(string configurationName)
 {
     this.Initialize();
     this.security = new NetMsmqSecurity();
     this.ApplyConfiguration(configurationName);
 }
 public NetMsmqBinding()
 {
     this.Initialize();
     this.security = new NetMsmqSecurity();
 }
 private static bool TryCreateSecurity(SecurityBindingElement sbe, UnifiedSecurityMode mode, out NetMsmqSecurity security)
 {
     if (sbe != null)
     {
         mode &= UnifiedSecurityMode.Both | UnifiedSecurityMode.Message;
     }
     else
     {
         mode &= ~(UnifiedSecurityMode.Both | UnifiedSecurityMode.Message);
     }
     NetMsmqSecurityMode mode2 = NetMsmqSecurityModeHelper.ToSecurityMode(mode);
     return NetMsmqSecurity.TryCreate(sbe, mode2, out security);
 }
Exemplo n.º 20
0
 //
 internal static bool TryCreate(SecurityBindingElement sbe, NetMsmqSecurityMode mode, out NetMsmqSecurity security)
 {
     security = null;
     MessageSecurityOverMsmq messageSecurity;
     if (!MessageSecurityOverMsmq.TryCreate(sbe, out messageSecurity))
         messageSecurity = null;
     security = new NetMsmqSecurity(mode, null, messageSecurity);
     return sbe == null || Config.SecurityElement.AreBindingsMatching(security.CreateMessageSecurity(), sbe, false);
 }
Exemplo n.º 21
0
		public NetMsmqBinding (NetMsmqSecurityMode securityMode)
		{
			security = new NetMsmqSecurity (securityMode);
		}
Exemplo n.º 22
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count > 3)
            {
                return(false);
            }

            SecurityBindingElement security = null;
            BinaryMessageEncodingBindingElement encoding  = null;
            MsmqTransportBindingElement         transport = null;

            foreach (BindingElement element in elements)
            {
                if (element is SecurityBindingElement)
                {
                    security = element as SecurityBindingElement;
                }
                else if (element is TransportBindingElement)
                {
                    transport = element as MsmqTransportBindingElement;
                }
                else if (element is MessageEncodingBindingElement)
                {
                    encoding = element as BinaryMessageEncodingBindingElement;
                }
                else
                {
                    return(false);
                }
            }

            UnifiedSecurityMode mode;

            if (!IsValidTransport(transport, out mode))
            {
                return(false);
            }

            if (encoding == null)
            {
                return(false);
            }

            NetMsmqSecurity netMsmqSecurity;

            if (!TryCreateSecurity(security, mode, out netMsmqSecurity))
            {
                return(false);
            }

            NetMsmqBinding netMsmqBinding = new NetMsmqBinding(netMsmqSecurity);

            netMsmqBinding.InitializeFrom(transport, encoding);
            if (!netMsmqBinding.IsBindingElementsMatch(transport, encoding))
            {
                return(false);
            }

            binding = netMsmqBinding;
            return(true);
        }
Exemplo n.º 23
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count > 3)
                return false;

            SecurityBindingElement security = null;
            BinaryMessageEncodingBindingElement encoding = null;
            MsmqTransportBindingElement transport = null;

            foreach (BindingElement element in elements)
            {
                if (element is SecurityBindingElement)
                    security = element as SecurityBindingElement;
                else if (element is TransportBindingElement)
                    transport = element as MsmqTransportBindingElement;
                else if (element is MessageEncodingBindingElement)
                    encoding = element as BinaryMessageEncodingBindingElement;
                else
                    return false;
            }

            UnifiedSecurityMode mode;
            if (!IsValidTransport(transport, out mode))
                return false;

            if (encoding == null)
                return false;

            NetMsmqSecurity netMsmqSecurity;
            if (!TryCreateSecurity(security, mode, out netMsmqSecurity))
                return false;

            NetMsmqBinding netMsmqBinding = new NetMsmqBinding(netMsmqSecurity);
            netMsmqBinding.InitializeFrom(transport, encoding);
            if (!netMsmqBinding.IsBindingElementsMatch(transport, encoding))
                return false;

            binding = netMsmqBinding;
            return true;
        }
Exemplo n.º 24
0
        public static List<NetMsmqBinding> GetNetMsmqBindings(string exeConfigPath)
        {
            var svcSection = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath);

            var configs = new List<NetMsmqBinding>();
            foreach (
                var section in
                    svcSection.Bindings.NetMsmqBinding.ConfiguredBindings
                        .Cast<NetMsmqBindingElement>())
            {
                var df = new NetMsmqBinding();
                var binding = new NetMsmqBinding
                {
                    Name = section.Name,
                    MaxBufferPoolSize = section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : df.MaxBufferPoolSize,
                    MaxReceivedMessageSize = section.MaxReceivedMessageSize > 0 ? section.MaxReceivedMessageSize : df.MaxReceivedMessageSize,
                    CloseTimeout = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : df.CloseTimeout,
                    OpenTimeout = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : df.OpenTimeout,
                    SendTimeout = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : df.SendTimeout,
                    ReceiveTimeout =
                        section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : df.ReceiveTimeout,

                    MaxRetryCycles = section.MaxRetryCycles > 0 ? section.MaxRetryCycles : df.MaxRetryCycles,
                    ReceiveRetryCount = section.ReceiveRetryCount > 0 ? section.ReceiveRetryCount : df.ReceiveRetryCount,
                    RetryCycleDelay = section.RetryCycleDelay != TimeSpan.Zero ? section.RetryCycleDelay : df.RetryCycleDelay,
                    TimeToLive = section.TimeToLive != TimeSpan.Zero ? section.TimeToLive : df.TimeToLive,

                    DeadLetterQueue = section.DeadLetterQueue,
                    Durable = section.Durable,
                    ExactlyOnce = section.ExactlyOnce,
                    ReceiveErrorHandling = section.ReceiveErrorHandling,
                    UseSourceJournal = section.UseSourceJournal,
                    UseMsmqTracing = section.UseMsmqTracing,
                    QueueTransferProtocol = section.QueueTransferProtocol,
                    UseActiveDirectory = section.UseActiveDirectory
                };

                var readerQuotasSection = section.ReaderQuotas;
                var readerQuotas = new System.Xml.XmlDictionaryReaderQuotas();
                if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0)
                {
                    readerQuotas.MaxDepth = readerQuotasSection.MaxDepth;
                    readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength;
                    readerQuotas.MaxArrayLength = readerQuotasSection.MaxArrayLength;
                    readerQuotas.MaxBytesPerRead = readerQuotasSection.MaxBytesPerRead;
                    readerQuotas.MaxNameTableCharCount = readerQuotasSection.MaxNameTableCharCount;
                }
                else
                {
                    readerQuotas = null;
                }
                var msmqSecurity = new NetMsmqSecurity {Mode = section.Security.Mode};
                var securityTransportSection = section.Security.Transport;
                var msmqSecurityTransport = new MsmqTransportSecurity
                {
                    MsmqAuthenticationMode = securityTransportSection.MsmqAuthenticationMode,
                    MsmqEncryptionAlgorithm = securityTransportSection.MsmqEncryptionAlgorithm,
                    MsmqProtectionLevel = securityTransportSection.MsmqProtectionLevel,
                    MsmqSecureHashAlgorithm = securityTransportSection.MsmqSecureHashAlgorithm
                };
                var msmqSecurityMessage = new MessageSecurityOverMsmq
                {
                    ClientCredentialType = section.Security.Message.ClientCredentialType
                };
                msmqSecurity.Message = msmqSecurityMessage;
                msmqSecurity.Transport = msmqSecurityTransport;
                binding.Security = msmqSecurity;
                if (readerQuotas != null)
                {
                    binding.ReaderQuotas = readerQuotas;
                }
                configs.Add(binding);

            }
            return configs;
        }
Exemplo n.º 25
0
        static bool TryCreateSecurity(SecurityBindingElement sbe, UnifiedSecurityMode mode, out NetMsmqSecurity security)
        {
            if (sbe != null)
                mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.Both;
            else
                mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.Both);

            NetMsmqSecurityMode netMsmqSecurityMode = NetMsmqSecurityModeHelper.ToSecurityMode(mode);
            Fx.Assert(NetMsmqSecurityModeHelper.IsDefined(netMsmqSecurityMode), string.Format("Invalid NetMsmqSecurityMode value: {0}.", netMsmqSecurityMode.ToString()));

            if (NetMsmqSecurity.TryCreate(sbe, netMsmqSecurityMode, out security))
            {
                return true;
            }
            return false;
        }
Exemplo n.º 26
0
 NetMsmqBinding(NetMsmqSecurity security)
 {
     Initialize();
     Fx.Assert(security != null, "Invalid (null) NetMsmqSecurity value");
     this.security = security;
 }
Exemplo n.º 27
0
 public NetMsmqBinding(string configurationName)
 {
     this.Initialize();
     this.security = new NetMsmqSecurity();
     this.ApplyConfiguration(configurationName);
 }
 public NetMsmqBinding(NetMsmqSecurityMode securityMode)
 {
     security = new NetMsmqSecurity(securityMode);
 }