Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Configuration / SecurityElement.cs
blob6866807d7b63ccb1d357665656cb5711d734e18b
1 //------------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------------------------
5 namespace System.ServiceModel.Configuration
7 using System.ComponentModel;
8 using System.ServiceModel.Channels;
9 using System.ServiceModel.Description;
10 using System.Configuration;
11 using System.Globalization;
12 using System.Net.Security;
13 using System.ServiceModel.Security;
14 using System.ServiceModel.Security.Tokens;
15 using System.Runtime.Remoting.Messaging;
16 using System.Xml;
17 using System.Collections.ObjectModel;
18 using System.Collections.Generic;
19 using System.IO;
21 public sealed partial class SecurityElement : SecurityElementBase
23 public SecurityElement()
25 this.SecureConversationBootstrap.IsSecurityElementBootstrap = true; // Tell the bootstrap it's potentially okay to optimize itself out of config representation
28 [ConfigurationProperty(ConfigurationStrings.SecureConversationBootstrap)]
29 public SecurityElementBase SecureConversationBootstrap
31 get { return (SecurityElementBase)base[ConfigurationStrings.SecureConversationBootstrap]; }
34 public override void CopyFrom(ServiceModelExtensionElement from)
36 base.CopyFrom(from);
38 SecurityElement source = (SecurityElement)from;
40 #pragma warning suppress 56506 //Microsoft; base.CopyFrom() checks for 'from' being null
41 if (PropertyValueOrigin.Default != source.ElementInformation.Properties[ConfigurationStrings.SecureConversationBootstrap].ValueOrigin)
42 this.SecureConversationBootstrap.CopyFrom(source.SecureConversationBootstrap);
45 protected internal override BindingElement CreateBindingElement(bool createTemplateOnly)
47 SecurityBindingElement result;
48 if (this.AuthenticationMode == AuthenticationMode.SecureConversation)
50 if (this.SecureConversationBootstrap == null)
51 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SecureConversationNeedsBootstrapSecurity)));
52 if (this.SecureConversationBootstrap.AuthenticationMode == AuthenticationMode.SecureConversation)
53 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SecureConversationBootstrapCannotUseSecureConversation)));
54 SecurityBindingElement bootstrapSecurity = (SecurityBindingElement)this.SecureConversationBootstrap.CreateBindingElement(createTemplateOnly);
55 result = SecurityBindingElement.CreateSecureConversationBindingElement(bootstrapSecurity, this.RequireSecurityContextCancellation);
57 else
59 result = (SecurityBindingElement)base.CreateBindingElement(createTemplateOnly);
62 this.ApplyConfiguration(result);
64 return result;
67 protected override void AddBindingTemplates(Dictionary<AuthenticationMode, SecurityBindingElement> bindingTemplates)
69 base.AddBindingTemplates(bindingTemplates);
70 AddBindingTemplate(bindingTemplates, AuthenticationMode.SecureConversation);
73 void InitializeSecureConversationParameters(SecureConversationSecurityTokenParameters sc, bool initializeNestedBindings)
75 SetPropertyValueIfNotDefaultValue(ConfigurationStrings.RequireSecurityContextCancellation, sc.RequireCancellation);
76 this.CanRenewSecurityContextToken = sc.CanRenewSession; // can't use default value optimization here because ApplyConfiguration relies on the runtime default instead, which is the opposite of the config default
77 if (sc.BootstrapSecurityBindingElement != null)
79 this.SecureConversationBootstrap.InitializeFrom(sc.BootstrapSecurityBindingElement, initializeNestedBindings);
83 protected override void InitializeNestedTokenParameterSettings(SecurityTokenParameters sp, bool initializeNestedBindings)
85 if (sp is SecureConversationSecurityTokenParameters)
86 this.InitializeSecureConversationParameters((SecureConversationSecurityTokenParameters)sp, initializeNestedBindings);
87 else
88 base.InitializeNestedTokenParameterSettings(sp, initializeNestedBindings);