public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters) { //see if ChunkingBindingParameter already exists ChunkingBindingParameter param = parameters.Find<ChunkingBindingParameter>(); if (param == null) { param = new ChunkingBindingParameter(); parameters.Add(param); } if ((appliesTo & ChunkingAppliesTo.InMessage) == ChunkingAppliesTo.InMessage) { //add input message's action to ChunkingBindingParameter param.AddAction(description.Messages[0].Action); } if (!description.IsOneWay && ((appliesTo & ChunkingAppliesTo.OutMessage) == ChunkingAppliesTo.OutMessage)) { //add output message's action to ChunkingBindingParameter param.AddAction(description.Messages[1].Action); } }
void IServiceBehavior.AddBindingParameters(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters) { if (parameters == null) { throw FxTrace.Exception.ArgumentNull("parameters"); } parameters.Add(this.virtualPathExtension); }
void IServiceBehavior.AddBindingParameters(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters) { if (parameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters")); } parameters.Add(this); }
/// <summary> /// Adds the binding parameters. /// </summary> /// <param name="serviceEndpoint">The service endpoint.</param> /// <param name="parameters">The parameters.</param> void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } ServiceDebugBehavior debugBehavior = parameters.Find<ServiceDebugBehavior>(); if (debugBehavior == null && this.serviceDebugBehavior != null) { parameters.Add(this.serviceDebugBehavior); } DispatcherSynchronizationBehavior synchronizationBehavior = parameters.Find<DispatcherSynchronizationBehavior>(); if (synchronizationBehavior == null && this.dispatcherSynchronizationBehavior != null) { parameters.Add(this.dispatcherSynchronizationBehavior); } }
static Dictionary<DirectionalAction, TransactionFlowOption> EnsureDictionary(BindingParameterCollection parameters) { Dictionary<DirectionalAction, TransactionFlowOption> dictionary = parameters.Find<Dictionary<DirectionalAction, TransactionFlowOption>>(); if (dictionary == null) { dictionary = new Dictionary<DirectionalAction, TransactionFlowOption>(); parameters.Add(dictionary); } return dictionary; }
StreamSecurityUpgradeProvider CreateClientProvider (params object [] parameters) { SslStreamSecurityBindingElement bel = new SslStreamSecurityBindingElement (); BindingParameterCollection pl = new BindingParameterCollection (); foreach (object o in parameters) pl.Add (o); BindingContext ctx = new BindingContext ( new CustomBinding (new HttpTransportBindingElement ()), pl); return bel.BuildClientStreamUpgradeProvider (ctx) as StreamSecurityUpgradeProvider; }
BuildChannelListener <TChannel> ( Uri listenUri, params object [] parameters) where TChannel : class, IChannel { BindingParameterCollection pl = new BindingParameterCollection(); foreach (object o in parameters) { pl.Add(o); } return(BuildChannelListener <TChannel> (listenUri, pl)); }
protected override void InitializeRuntime() { BindingParameterCollection bpc = new BindingParameterCollection(); VirtualPathExtension virtualPathExtension = this.Extensions.Find<VirtualPathExtension>(); if (virtualPathExtension != null) { bpc.Add(virtualPathExtension); } BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); IChannelListener<IReplyChannel> listener = basicHttpBinding.BuildChannelListener<IReplyChannel>(interestedUri, bpc); CustomChannelDispatcher channelDispatcher = new CustomChannelDispatcher(serviceManager, listener); this.ChannelDispatchers.Add(channelDispatcher); }
BuildChannelListener <TChannel> ( Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, params object [] parameters) where TChannel : class, IChannel { BindingParameterCollection pl = new BindingParameterCollection(); foreach (object o in parameters) { pl.Add(o); } return(BuildChannelListener <TChannel> ( listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, pl)); }
// deep clone .ctor(). BindingContext(CustomBinding binding, BindingParameterCollection parms, BindingElementCollection elems, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode) { this.binding = new CustomBinding(binding); parameters = new BindingParameterCollection(); foreach (var item in parms) { parameters.Add(item); } this.elements = new BindingElementCollection(); foreach (var item in elems) { this.elements.Add(item); } listen_uri_base = listenUriBaseAddress; listen_uri_relative = listenUriRelativeAddress; listen_uri_mode = listenUriMode; }
private ChannelDispatcher BuildChannelDispatcher(Uri listenUri, ServiceHostBase host) { BindingParameterCollection parameters = new BindingParameterCollection(); VirtualPathExtension item = host.Extensions.Find<VirtualPathExtension>(); if (item != null) { parameters.Add(item); } IChannelListener<IReplyChannel> listener = null; WebHttpBinding binding = new WebHttpBinding(); if (binding.CanBuildChannelListener<IReplyChannel>(parameters)) { listener = binding.BuildChannelListener<IReplyChannel>(listenUri, parameters); } ChannelDispatcher channelDispatcher = new ChannelDispatcher(listener) { MessageVersion = MessageVersion.None }; return channelDispatcher; }
BindingElementCollection elements; // for internal use public BindingContext(CustomBinding binding, BindingParameterCollection parms) { if (binding == null) { throw new ArgumentNullException("binding"); } if (parms == null) { throw new ArgumentNullException("parms"); } this.binding = binding; parameters = new BindingParameterCollection(); foreach (var item in parms) { parameters.Add(item); } this.elements = new BindingElementCollection(); foreach (var item in binding.Elements) { this.elements.Add(item); } }
/// <summary> /// Called to apply the configuration on the endpoint level. /// </summary> /// <param name="webHttpRelayBinding">Azure Http endpoint.</param> /// <returns>The <see cref="BindingParameterCollection"/> to use when building the <see cref="IChannelListener"/> or null if no binding parameters are present.</returns> protected virtual BindingParameterCollection OnConfigureBinding(Binding webHttpRelayBinding) { if (webHttpRelayBinding == null) { throw new ArgumentNullException("webHttpRelayBinding"); } var bindingParameters = new BindingParameterCollection(); bindingParameters.Add(new TransportClientEndpointBehavior(TokenProvider.CreateSharedSecretTokenProvider(IssuerName, IssuerSecret))); return bindingParameters; }
public void SendRequestWithSignatureMessagePart () { CustomBinding b = CreateBinding (); ChannelProtectionRequirements cp = new ChannelProtectionRequirements (); cp.IncomingSignatureParts.AddParts (new MessagePartSpecification (true), "myAction"); cp.IncomingEncryptionParts.AddParts (new MessagePartSpecification (true), "myAction"); BindingParameterCollection parameters = new BindingParameterCollection (); parameters.Add (cp); IChannelFactory<IRequestChannel> f = b.BuildChannelFactory<IRequestChannel> (parameters); f.Open (); IRequestChannel ch = f.CreateChannel (CreateX509EndpointAddress ("stream:dummy")); ch.Open (); ch.Request (Message.CreateMessage (b.MessageVersion, "myAction")); }
IChannelFactory<IRequestChannel> CreateDefaultServiceCertFactory () { CustomBinding b = CreateBinding (delegate (Message req) { return null; }); ClientCredentials cred = new ClientCredentials (); cred.ServiceCertificate.DefaultCertificate = new X509Certificate2 ("Test/Resources/test.pfx", "mono"); BindingParameterCollection parameters = new BindingParameterCollection (); parameters.Add (cred); ChannelProtectionRequirements cp = new ChannelProtectionRequirements (); cp.IncomingSignatureParts.AddParts ( new MessagePartSpecification (true), "http://tempuri.org/MyAction"); cp.IncomingEncryptionParts.AddParts ( new MessagePartSpecification (true), "http://tempuri.org/MyAction"); parameters.Add (cp); return b.BuildChannelFactory<IRequestChannel> (parameters); }
public void OpenRequestNonAuthenticatable () { SymmetricSecurityBindingElement sbe = new SymmetricSecurityBindingElement (); sbe.ProtectionTokenParameters = new UserNameSecurityTokenParameters (); Binding binding = new CustomBinding (sbe, new HandlerTransportBindingElement (null)); BindingParameterCollection pl = new BindingParameterCollection (); ClientCredentials cred = new ClientCredentials (); cred.UserName.UserName = "******"; pl.Add (cred); IChannelFactory<IRequestChannel> f = binding.BuildChannelFactory<IRequestChannel> (pl); f.Open (); IRequestChannel ch = f.CreateChannel (new EndpointAddress ("stream:dummy")); try { ch.Open (); Assert.Fail ("NotSupportedException is expected."); } catch (NotSupportedException) { } }
void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters) { if (bindingParameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingParameters"); } SecurityCredentialsManager manager = bindingParameters.Find<SecurityCredentialsManager>(); if (manager != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MultipleSecurityCredentialsManagersInChannelBindingParameters", new object[] { manager }))); } bindingParameters.Add(this); }
void CreateSecurityProtocolFactory() { SecurityProtocolFactory incomingProtocolFactory; SecurityProtocolFactory outgoingProtocolFactory; ChannelProtectionRequirements protectionRequirements; lock (ThisLock) { if (null != securityProtocolFactory) { return; } TimeoutHelper timeoutHelper = new TimeoutHelper(ServiceDefaults.SendTimeout); if (!enableSigning) { outgoingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); incomingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); } else { X509Certificate2 cert = credManager.Certificate; if (cert != null) { SecurityBindingElement securityBindingElement = SecurityBindingElement.CreateCertificateSignatureBindingElement(); securityBindingElement.ReaderQuotas = this.readerQuotas; BindingParameterCollection bpc = new BindingParameterCollection(); if (protection == null) { protectionRequirements = new ChannelProtectionRequirements(); } else { protectionRequirements = new ChannelProtectionRequirements(protection); } ApplySigningRequirements(protectionRequirements.IncomingSignatureParts); ApplySigningRequirements(protectionRequirements.OutgoingSignatureParts); bpc.Add(protectionRequirements); bpc.Add(this.auditBehavior); bpc.Add(credManager); BindingContext context = new BindingContext(new CustomBinding(securityBindingElement), bpc); outgoingProtocolFactory = securityBindingElement.CreateSecurityProtocolFactory <IOutputChannel>(context, credManager, false, null); } else { outgoingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); } SecurityTokenResolver resolver; X509SecurityTokenAuthenticator auth = tokenManager.CreateSecurityTokenAuthenticator(PeerSecurityCredentialsManager.PeerClientSecurityTokenManager.CreateRequirement(SecurityTokenTypes.X509Certificate, true), out resolver) as X509SecurityTokenAuthenticator; if (auth != null) { SecurityBindingElement securityBindingElement = SecurityBindingElement.CreateCertificateSignatureBindingElement(); securityBindingElement.ReaderQuotas = this.readerQuotas; BindingParameterCollection bpc = new BindingParameterCollection(); if (protection == null) { protectionRequirements = new ChannelProtectionRequirements(); } else { protectionRequirements = new ChannelProtectionRequirements(protection); } ApplySigningRequirements(protectionRequirements.IncomingSignatureParts); ApplySigningRequirements(protectionRequirements.OutgoingSignatureParts); bpc.Add(protectionRequirements); bpc.Add(this.auditBehavior); bpc.Add(credManager); BindingContext context = new BindingContext(new CustomBinding(securityBindingElement), bpc); incomingProtocolFactory = securityBindingElement.CreateSecurityProtocolFactory <IOutputChannel>(context, credManager, true, null); } else { incomingProtocolFactory = new PeerDoNothingSecurityProtocolFactory(); } } DuplexSecurityProtocolFactory tempFactory = new DuplexSecurityProtocolFactory(outgoingProtocolFactory, incomingProtocolFactory); tempFactory.Open(true, timeoutHelper.RemainingTime()); securityProtocolFactory = tempFactory; } }
public void MessageSecurityManualProtection () { SymmetricSecurityBindingElement sbe = new SymmetricSecurityBindingElement (); sbe.ProtectionTokenParameters = new X509SecurityTokenParameters (); RequestSender sender = delegate (Message input) { MessageBuffer buf = input.CreateBufferedCopy (0x10000); using (XmlWriter w = XmlWriter.Create (Console.Error)) { buf.CreateMessage ().WriteMessage (w); } return buf.CreateMessage (); }; CustomBinding binding = new CustomBinding ( sbe, new TextMessageEncodingBindingElement (), new HandlerTransportBindingElement (sender)); EndpointAddress address = new EndpointAddress ( new Uri ("http://localhost:8080"), new X509CertificateEndpointIdentity (new X509Certificate2 ("Test/Resources/test.pfx", "mono"))); ChannelProtectionRequirements reqs = new ChannelProtectionRequirements (); reqs.OutgoingSignatureParts.AddParts ( new MessagePartSpecification (new XmlQualifiedName ("SampleValue", "urn:foo")), "urn:myaction"); BindingParameterCollection parameters = new BindingParameterCollection (); parameters.Add (reqs); /* SymmetricSecurityBindingElement innersbe = new SymmetricSecurityBindingElement (); innersbe.ProtectionTokenParameters = new X509SecurityTokenParameters (); sbe.ProtectionTokenParameters = new SecureConversationSecurityTokenParameters ( innersbe, false, reqs); */ IChannelFactory<IRequestChannel> cf = binding.BuildChannelFactory<IRequestChannel> (parameters); cf.Open (); IRequestChannel ch = cf.CreateChannel (address); ch.Open (); try { ch.Request (Message.CreateMessage (MessageVersion.None, "urn:myaction", new SampleValue ())); } finally { ch.Close (); } }
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection parameters) { // get Contract info security needs, and put in BindingParameterCollection ISecurityCapabilities isc = null; BindingElementCollection elements = endpoint.Binding.CreateBindingElements(); for (int i = 0; i < elements.Count; ++i) { if (!(elements[i] is ITransportTokenAssertionProvider)) { ISecurityCapabilities tmp = elements[i].GetIndividualProperty<ISecurityCapabilities>(); if (tmp != null) { isc = tmp; break; } } } if (isc != null) { // ensure existence of binding parameter ChannelProtectionRequirements requirements = parameters.Find<ChannelProtectionRequirements>(); if (requirements == null) { requirements = new ChannelProtectionRequirements(); parameters.Add(requirements); } MessageEncodingBindingElement encoding = elements.Find<MessageEncodingBindingElement>(); // use endpoint.Binding.Version if (encoding != null && encoding.MessageVersion.Addressing == AddressingVersion.None) { // This binding does not support response actions, so... requirements.Add(ChannelProtectionRequirements.CreateFromContractAndUnionResponseProtectionRequirements(endpoint.Contract, isc, isForClient)); } else { requirements.Add(ChannelProtectionRequirements.CreateFromContract(endpoint.Contract, isc, isForClient)); } } }
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection parameters) { // get Contract info security needs, and put in BindingParameterCollection ISecurityCapabilities isc = null; BindingElementCollection elements = endpoint.Binding.CreateBindingElements(); if (isc != null) { // ensure existence of binding parameter ChannelProtectionRequirements requirements = parameters.Find<ChannelProtectionRequirements>(); if (requirements == null) { requirements = new ChannelProtectionRequirements(); parameters.Add(requirements); } MessageEncodingBindingElement encoding = elements.Find<MessageEncodingBindingElement>(); // use endpoint.Binding.Version if (encoding != null && encoding.MessageVersion.Addressing == AddressingVersion.None) { // This binding does not support response actions, so... requirements.Add(ChannelProtectionRequirements.CreateFromContractAndUnionResponseProtectionRequirements(endpoint.Contract, isc, _isForClient)); } else { requirements.Add(ChannelProtectionRequirements.CreateFromContract(endpoint.Contract, isc, _isForClient)); } } }
void IServiceBehavior.AddBindingParameters(System.ServiceModel.Description.ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters) { if (parameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameters"); } SecurityCredentialsManager manager = parameters.Find<SecurityCredentialsManager>(); if (manager != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MultipleSecurityCredentialsManagersInServiceBindingParameters", new object[] { manager }))); } parameters.Add(this); }
private bool ContainsEncryptionParts(PolicyConversionContext policyContext, SecurityBindingElement security) { if (policyContext.Contract == NullContract) { return true; } if ((security.EndpointSupportingTokenParameters.SignedEncrypted.Count > 0) || (security.OptionalEndpointSupportingTokenParameters.SignedEncrypted.Count > 0)) { return true; } foreach (SupportingTokenParameters parameters in security.OperationSupportingTokenParameters.Values) { if (parameters.SignedEncrypted.Count > 0) { return true; } } foreach (SupportingTokenParameters parameters2 in security.OptionalOperationSupportingTokenParameters.Values) { if (parameters2.SignedEncrypted.Count > 0) { return true; } } BindingParameterCollection parameterCollection = new BindingParameterCollection(); parameterCollection.Add(ChannelProtectionRequirements.CreateFromContract(policyContext.Contract, policyContext.BindingElements.Find<SecurityBindingElement>().GetIndividualProperty<ISecurityCapabilities>(), false)); ChannelProtectionRequirements requirements = SecurityBindingElement.ComputeProtectionRequirements(security, parameterCollection, policyContext.BindingElements, true); requirements.MakeReadOnly(); GetSecurityPolicyDriver(security.MessageSecurityVersion); foreach (OperationDescription description in policyContext.Contract.Operations) { foreach (MessageDescription description2 in description.Messages) { MessagePartSpecification specification; ScopedMessagePartSpecification incomingEncryptionParts; if (description2.Direction == MessageDirection.Input) { incomingEncryptionParts = requirements.IncomingEncryptionParts; } else { incomingEncryptionParts = requirements.OutgoingEncryptionParts; } if (incomingEncryptionParts.TryGetParts(description2.Action, out specification) && !specification.IsEmpty()) { return true; } } foreach (FaultDescription description3 in description.Faults) { MessagePartSpecification specification3; if (requirements.OutgoingEncryptionParts.TryGetParts(description3.Action, out specification3) && !specification3.IsEmpty()) { return true; } } } return false; }
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection parameters) { ISecurityCapabilities bindingElement = null; BindingElementCollection elements = endpoint.Binding.CreateBindingElements(); for (int i = 0; i < elements.Count; i++) { if (!(elements[i] is ITransportTokenAssertionProvider)) { ISecurityCapabilities individualProperty = elements[i].GetIndividualProperty<ISecurityCapabilities>(); if (individualProperty != null) { bindingElement = individualProperty; break; } } } if (bindingElement != null) { ChannelProtectionRequirements item = parameters.Find<ChannelProtectionRequirements>(); if (item == null) { item = new ChannelProtectionRequirements(); parameters.Add(item); } MessageEncodingBindingElement element = elements.Find<MessageEncodingBindingElement>(); if ((element != null) && (element.MessageVersion.Addressing == AddressingVersion.None)) { item.Add(ChannelProtectionRequirements.CreateFromContractAndUnionResponseProtectionRequirements(endpoint.Contract, bindingElement, this.isForClient)); } else { item.Add(ChannelProtectionRequirements.CreateFromContract(endpoint.Contract, bindingElement, this.isForClient)); } } }
void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint, BindingParameterCollection parameters) { parameters.Add (this); }
void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters) { if (parameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameters"); } if (this.serviceAuthenticationManager != null) { // throw if bindingParameters already has a AuthenticationManager ServiceAuthenticationManager otherAuthenticationManager = parameters.Find<ServiceAuthenticationManager>(); if (otherAuthenticationManager != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MultipleAuthenticationManagersInServiceBindingParameters, otherAuthenticationManager))); } parameters.Add(this.serviceAuthenticationManager); } if (this.authenticationSchemes != AuthenticationSchemes.None) { // throw if bindingParameters already has an AuthenticationSchemes AuthenticationSchemesBindingParameter otherAuthenticationSchemesBindingParameter = parameters.Find<AuthenticationSchemesBindingParameter>(); if (otherAuthenticationSchemesBindingParameter != null) { if (otherAuthenticationSchemesBindingParameter.AuthenticationSchemes != authenticationSchemes) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MultipleAuthenticationSchemesInServiceBindingParameters, otherAuthenticationSchemesBindingParameter.AuthenticationSchemes))); } } else { parameters.Add(new AuthenticationSchemesBindingParameter(this.authenticationSchemes)); } } }
void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection bindingParameters) { if (bindingParameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingParameters"); } // throw if bindingParameters already has a SecurityCredentialsManager SecurityCredentialsManager otherCredentialsManager = bindingParameters.Find<SecurityCredentialsManager>(); if (otherCredentialsManager != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.MultipleSecurityCredentialsManagersInChannelBindingParameters, otherCredentialsManager))); } bindingParameters.Add(this); }
void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters) { if (parameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parameters"); } ServiceDebugBehavior param = parameters.Find<ServiceDebugBehavior>(); if (param == null) { parameters.Add(this); } }
private void CreateSecurityProtocolFactory() { lock (this.ThisLock) { if (this.securityProtocolFactory == null) { SecurityProtocolFactory factory; SecurityProtocolFactory factory2; TimeoutHelper helper = new TimeoutHelper(ServiceDefaults.SendTimeout); if (!this.enableSigning) { factory2 = new PeerDoNothingSecurityProtocolFactory(); factory = new PeerDoNothingSecurityProtocolFactory(); } else { ChannelProtectionRequirements requirements; SecurityTokenResolver resolver; if (this.credManager.Certificate != null) { SecurityBindingElement element = SecurityBindingElement.CreateCertificateSignatureBindingElement(); element.ReaderQuotas = this.readerQuotas; BindingParameterCollection parameters = new BindingParameterCollection(); if (this.protection == null) { requirements = new ChannelProtectionRequirements(); } else { requirements = new ChannelProtectionRequirements(this.protection); } this.ApplySigningRequirements(requirements.IncomingSignatureParts); this.ApplySigningRequirements(requirements.OutgoingSignatureParts); parameters.Add(requirements); parameters.Add(this.auditBehavior); parameters.Add(this.credManager); BindingContext context = new BindingContext(new CustomBinding(new BindingElement[] { element }), parameters); factory2 = element.CreateSecurityProtocolFactory <IOutputChannel>(context, this.credManager, false, null); } else { factory2 = new PeerDoNothingSecurityProtocolFactory(); } if (this.tokenManager.CreateSecurityTokenAuthenticator(PeerSecurityCredentialsManager.PeerClientSecurityTokenManager.CreateRequirement(SecurityTokenTypes.X509Certificate, true), out resolver) is X509SecurityTokenAuthenticator) { SecurityBindingElement element2 = SecurityBindingElement.CreateCertificateSignatureBindingElement(); element2.ReaderQuotas = this.readerQuotas; BindingParameterCollection parameters2 = new BindingParameterCollection(); if (this.protection == null) { requirements = new ChannelProtectionRequirements(); } else { requirements = new ChannelProtectionRequirements(this.protection); } this.ApplySigningRequirements(requirements.IncomingSignatureParts); this.ApplySigningRequirements(requirements.OutgoingSignatureParts); parameters2.Add(requirements); parameters2.Add(this.auditBehavior); parameters2.Add(this.credManager); BindingContext context2 = new BindingContext(new CustomBinding(new BindingElement[] { element2 }), parameters2); factory = element2.CreateSecurityProtocolFactory <IOutputChannel>(context2, this.credManager, true, null); } else { factory = new PeerDoNothingSecurityProtocolFactory(); } } DuplexSecurityProtocolFactory factory3 = new DuplexSecurityProtocolFactory(factory2, factory); factory3.Open(true, helper.RemainingTime()); this.securityProtocolFactory = factory3; } } }
void IServiceBehavior.AddBindingParameters ( ServiceDescription description, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters) { parameters.Add (this); }
internal virtual void AddMetadataBindingParameters(Uri listenUri, KeyedByTypeCollection<IServiceBehavior> serviceBehaviors, BindingParameterCollection bindingParameters) { bindingParameters.Add(new ServiceMetadataExtension.MetadataBindingParameter()); }
private BindingParameterCollection AddCredentialsToBindingParameters() { BindingParameterCollection bindingParameters = new BindingParameterCollection(); bindingParameters.Add(_credentials); return bindingParameters; }
//This method generates the BindingParameterCollection in the same way it is created during DispatcherBuilder.InitializeServiceHost internal static BindingParameterCollection GetBindingParameters(ServiceHostBase serviceHost, Collection<ServiceEndpoint> endpoints) { BindingParameterCollection parameters = new BindingParameterCollection(); parameters.Add(new ThreadSafeMessageFilterTable<EndpointAddress>()); foreach (IServiceBehavior behavior in serviceHost.Description.Behaviors) { behavior.AddBindingParameters(serviceHost.Description, serviceHost, endpoints, parameters); } foreach (ServiceEndpoint endpoint in endpoints) { DispatcherBuilder.SecurityContractInformationEndpointBehavior.ServerInstance.AddBindingParameters(endpoint, parameters); DispatcherBuilder.AddBindingParameters(endpoint, parameters); } return parameters; }
internal override void AddMetadataBindingParameters(Uri listenUri, KeyedByTypeCollection<IServiceBehavior> serviceBehaviors, BindingParameterCollection bindingParameters) { if (serviceBehaviors.Find<HostedBindingBehavior>() != null) { bindingParameters.Add(new HostedMetadataBindingParameter()); } VirtualPathExtension virtualPathExtension = bindingParameters.Find<VirtualPathExtension>(); if (virtualPathExtension != null) { AuthenticationSchemes hostSupportedAuthenticationSchemes = AspNetEnvironment.Current.GetAuthenticationSchemes(listenUri); if (hostSupportedAuthenticationSchemes != AuthenticationSchemes.None) { if (bindingParameters.Find<AuthenticationSchemesBindingParameter>() == null) { bindingParameters.Add(new AuthenticationSchemesBindingParameter(hostSupportedAuthenticationSchemes)); } } } base.AddMetadataBindingParameters(listenUri, serviceBehaviors, bindingParameters); }
// This api checks whether or not the message will or may contain Encrypted parts // to decide whether or not to emit sp:EncryptSignature on Binding assertion. // 1) (Optional)EndpointSupporting. // 2) (Optional)OperationSupporting. // 3) In/Out/Fault Message ProtectionLevel for each Operation. bool ContainsEncryptionParts(PolicyConversionContext policyContext, SecurityBindingElement security) { // special case for RST/RSTR since we hard coded the security for them if (policyContext.Contract == NullContract) return true; if (security.EndpointSupportingTokenParameters.SignedEncrypted.Count > 0 || security.OptionalEndpointSupportingTokenParameters.SignedEncrypted.Count > 0) { return true; } foreach (SupportingTokenParameters r in security.OperationSupportingTokenParameters.Values) { if (r.SignedEncrypted.Count > 0) { return true; } } foreach (SupportingTokenParameters r in security.OptionalOperationSupportingTokenParameters.Values) { if (r.SignedEncrypted.Count > 0) { return true; } } BindingParameterCollection bindingParameters = new BindingParameterCollection(); bindingParameters.Add(ChannelProtectionRequirements.CreateFromContract(policyContext.Contract, policyContext.BindingElements.Find<SecurityBindingElement>().GetIndividualProperty<ISecurityCapabilities>(), false)); ChannelProtectionRequirements protectionRequirements = SecurityBindingElement.ComputeProtectionRequirements(security, bindingParameters, policyContext.BindingElements, true); protectionRequirements.MakeReadOnly(); WSSecurityPolicy sp = WSSecurityPolicy.GetSecurityPolicyDriver(security.MessageSecurityVersion); foreach (OperationDescription operation in policyContext.Contract.Operations) { // export policy for application messages foreach (MessageDescription message in operation.Messages) { MessagePartSpecification parts; ScopedMessagePartSpecification scopedParts; // confidentiality if (message.Direction == MessageDirection.Input) { scopedParts = protectionRequirements.IncomingEncryptionParts; } else { scopedParts = protectionRequirements.OutgoingEncryptionParts; } if (scopedParts.TryGetParts(message.Action, out parts)) { if (!parts.IsEmpty()) { return true; } } } // export policy for faults foreach (FaultDescription fault in operation.Faults) { MessagePartSpecification parts; // confidentiality if (protectionRequirements.OutgoingEncryptionParts.TryGetParts(fault.Action, out parts)) { if (!parts.IsEmpty()) { return true; } } } } return false; }
void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { bindingParameters.Add(new HostedMetadataBindingParameter()); }