SecurityElement.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 / Configuration / SecurityElement.cs / 1 / SecurityElement.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.ServiceModel.Configuration 
{
    using System.ComponentModel; 
    using System.ServiceModel.Channels; 
    using System.ServiceModel.Description;
    using System.Configuration; 
    using System.Globalization;
    using System.Net.Security;
    using System.ServiceModel.Security;
    using System.ServiceModel.Security.Tokens; 
    using System.Runtime.Remoting.Messaging;
    using System.Xml; 
    using System.Collections.ObjectModel; 
    using System.Collections.Generic;
    using System.IO; 

    public sealed partial class SecurityElement : SecurityElementBase
    {
        public SecurityElement() 
        {
        } 
 
        [ConfigurationProperty(ConfigurationStrings.SecureConversationBootstrap)]
        public SecurityElementBase SecureConversationBootstrap 
        {
            get { return (SecurityElementBase)base[ConfigurationStrings.SecureConversationBootstrap]; }
        }
 
        public override void CopyFrom(ServiceModelExtensionElement from)
        { 
            base.CopyFrom(from); 

            SecurityElement source = (SecurityElement)from; 

#pragma warning suppress 56506 //[....]; base.CopyFrom() checks for 'from' being null
            if (PropertyValueOrigin.Default != source.ElementInformation.Properties[ConfigurationStrings.SecureConversationBootstrap].ValueOrigin)
                this.SecureConversationBootstrap.CopyFrom(source.SecureConversationBootstrap); 
        }
 
        protected internal override BindingElement CreateBindingElement(bool createTemplateOnly) 
        {
            SecurityBindingElement result; 
            if (this.AuthenticationMode == AuthenticationMode.SecureConversation)
            {
                if (this.SecureConversationBootstrap == null)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SecureConversationNeedsBootstrapSecurity))); 
                if (this.SecureConversationBootstrap.AuthenticationMode == AuthenticationMode.SecureConversation)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SecureConversationBootstrapCannotUseSecureConversation))); 
                SecurityBindingElement bootstrapSecurity = (SecurityBindingElement)this.SecureConversationBootstrap.CreateBindingElement(createTemplateOnly); 
                result = SecurityBindingElement.CreateSecureConversationBindingElement(bootstrapSecurity, this.RequireSecurityContextCancellation);
            } 
            else
            {
                result = (SecurityBindingElement)base.CreateBindingElement(createTemplateOnly);
            } 

            this.ApplyConfiguration(result); 
 
            return result;
        } 

        protected override void AddBindingTemplates(Dictionary bindingTemplates)
        {
            base.AddBindingTemplates(bindingTemplates); 
            AddBindingTemplate(bindingTemplates, AuthenticationMode.SecureConversation);
        } 
 
        void InitializeSecureConversationParameters(SecureConversationSecurityTokenParameters sc, bool initializeNestedBindings)
        { 
            this.RequireSecurityContextCancellation = sc.RequireCancellation;
            if (sc.BootstrapSecurityBindingElement != null)
            {
                this.SecureConversationBootstrap.InitializeFrom(sc.BootstrapSecurityBindingElement, initializeNestedBindings); 
            }
        } 
 
        protected override void InitializeNestedTokenParameterSettings(SecurityTokenParameters sp, bool initializeNestedBindings)
        { 
            if (sp is SecureConversationSecurityTokenParameters)
                this.InitializeSecureConversationParameters((SecureConversationSecurityTokenParameters)sp, initializeNestedBindings);
            else
                base.InitializeNestedTokenParameterSettings(sp, initializeNestedBindings); 
        }
    } 
} 

 


// 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