NetMsmqSecurity.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / NetMsmqSecurity.cs / 1 / NetMsmqSecurity.cs

                            //---------------------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------------------
namespace System.ServiceModel
{ 
    using System.Diagnostics;
    using System.Net.Security; 
    using System.ServiceModel.Channels; 
    using Config = System.ServiceModel.Configuration;
 
    public sealed class NetMsmqSecurity
    {
        internal const NetMsmqSecurityMode DefaultMode = NetMsmqSecurityMode.Transport;
 
        NetMsmqSecurityMode mode;
        MsmqTransportSecurity transportSecurity; 
        MessageSecurityOverMsmq messageSecurity; 

        internal NetMsmqSecurity() : this(DefaultMode, null, null) 
        {
        }

        internal NetMsmqSecurity(NetMsmqSecurityMode mode) : this(mode, null, null) 
        {
        } 
 
        NetMsmqSecurity(NetMsmqSecurityMode mode, MsmqTransportSecurity transportSecurity, MessageSecurityOverMsmq messageSecurity)
        { 
            DiagnosticUtility.DebugAssert(NetMsmqSecurityModeHelper.IsDefined(mode), string.Format("Invalid NetMsmqSecurityMode value: {0}.", mode.ToString()));

            this.mode = mode;
            this.transportSecurity = transportSecurity == null ? new MsmqTransportSecurity() : transportSecurity; 
            this.messageSecurity = messageSecurity == null ? new MessageSecurityOverMsmq() : messageSecurity;
        } 
 
        public NetMsmqSecurityMode Mode
        { 
            get { return this.mode; }
            set
            {
                if (!NetMsmqSecurityModeHelper.IsDefined(value)) 
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); 
                } 
                this.mode = value;
            } 
        }

        public MsmqTransportSecurity Transport
        { 
            get
            { 
                if (this.transportSecurity == null) 
                    this.transportSecurity = new MsmqTransportSecurity();
                return this.transportSecurity; 
            }
        }

        public MessageSecurityOverMsmq Message 
        {
            get 
            { 
                if (this.messageSecurity == null)
                    this.messageSecurity = new MessageSecurityOverMsmq(); 
                return this.messageSecurity;
            }
        }
 
        internal void ConfigureTransportSecurity(MsmqBindingElementBase msmq)
        { 
            if (this.mode == NetMsmqSecurityMode.Transport || this.mode == NetMsmqSecurityMode.Both) 
                msmq.MsmqTransportSecurity = this.Transport;
            else 
                msmq.MsmqTransportSecurity.Disable();
        }

        internal static bool IsConfiguredTransportSecurity(MsmqTransportBindingElement msmq, out UnifiedSecurityMode mode) 
        {
            if (msmq == null) 
            { 
                mode = UnifiedSecurityMode.None;
                return false; 
            }
            if (msmq.MsmqTransportSecurity.Enabled)
            {
                mode = UnifiedSecurityMode.Transport | UnifiedSecurityMode.Both; 
            }
            else 
            { 
                mode = UnifiedSecurityMode.None | UnifiedSecurityMode.Message;
            } 
            return true;
        }

        internal SecurityBindingElement CreateMessageSecurity() 
        {
            return this.Message.CreateSecurityBindingElement(); 
        } 

        // 
        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);
        } 
    }
}

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK