public bool TryGetParts(string action, bool excludeChannelScope, out MessagePartSpecification parts)
        {
            if (action == null)
            {
                action = MessageHeaders.WildcardAction;
            }
            parts = null;

            if (this.isReadOnly)
            {
                if (this.readOnlyNormalizedActionParts.ContainsKey(action))
                {
                    if (excludeChannelScope)
                    {
                        parts = this.actionParts[action];
                    }
                    else
                    {
                        parts = this.readOnlyNormalizedActionParts[action];
                    }
                }
            }
            else if (this.actionParts.ContainsKey(action))
            {
                MessagePartSpecification p = new MessagePartSpecification();
                p.Union(this.actionParts[action]);
                if (!excludeChannelScope)
                {
                    p.Union(this.channelParts);
                }
                parts = p;
            }

            return(parts != null);
        }
 private void AddParts(ref MessagePartSpecification parts1, MessagePartSpecification parts2)
 {
     if (parts1 == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parts1"));
     }
     if (parts2 == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parts2"));
     }
     if (!parts2.IsEmpty())
     {
         if (parts1.IsReadOnly)
         {
             MessagePartSpecification specification = new MessagePartSpecification();
             specification.Union(parts1);
             specification.Union(parts2);
             parts1 = specification;
         }
         else
         {
             parts1.Union(parts2);
         }
     }
 }
 public void MakeReadOnly()
 {
     if (!IsReadOnly)
     {
         _readOnlyNormalizedActionParts = new Dictionary <string, MessagePartSpecification>();
         foreach (string action in _actionParts.Keys)
         {
             MessagePartSpecification p = new MessagePartSpecification();
             p.Union(_actionParts[action]);
             p.Union(ChannelParts);
             p.MakeReadOnly();
             _readOnlyNormalizedActionParts[action] = p;
         }
         IsReadOnly = true;
     }
 }
 public void MakeReadOnly()
 {
     if (!this.isReadOnly)
     {
         this.readOnlyNormalizedActionParts = new Dictionary <string, MessagePartSpecification>();
         foreach (string action in this.actionParts.Keys)
         {
             MessagePartSpecification p = new MessagePartSpecification();
             p.Union(this.actionParts[action]);
             p.Union(this.channelParts);
             p.MakeReadOnly();
             this.readOnlyNormalizedActionParts[action] = p;
         }
         this.isReadOnly = true;
     }
 }
예제 #5
0
		public void UnionReadOnlyPart ()
		{
			MessagePartSpecification s =
				new MessagePartSpecification ();
			s.MakeReadOnly ();
			Assert.AreEqual (true, s.IsReadOnly, "#1");
			s.Union (new MessagePartSpecification ());
		}
예제 #6
0
        public ScopedMessagePartSpecification(ScopedMessagePartSpecification other)
            : this()
        {
            if (other == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("other"));
            }

            _channelParts.Union(other._channelParts);
            if (other._actionParts != null)
            {
                foreach (string action in other._actionParts.Keys)
                {
                    MessagePartSpecification p = new MessagePartSpecification();
                    p.Union(other._actionParts[action]);
                    _actionParts[action] = p;
                }
            }
        }
        public ScopedMessagePartSpecification(ScopedMessagePartSpecification other)
            : this()
        {
            if (other == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("other"));

            _channelParts.Union(other._channelParts);
            if (other._actionParts != null)
            {
                foreach (string action in other._actionParts.Keys)
                {
                    MessagePartSpecification p = new MessagePartSpecification();
                    p.Union(other._actionParts[action]);
                    _actionParts[action] = p;
                }
            }
        }
 public ScopedMessagePartSpecification(ScopedMessagePartSpecification other) : this()
 {
     if (other == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("other"));
     }
     this.channelParts.Union(other.channelParts);
     if (other.actionParts != null)
     {
         foreach (string str in other.actionParts.Keys)
         {
             MessagePartSpecification specification = new MessagePartSpecification();
             specification.Union(other.actionParts[str]);
             this.actionParts[str] = specification;
         }
     }
 }
예제 #9
0
 public ScopedMessagePartSpecification(ScopedMessagePartSpecification other) : this()
 {
     if (other == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("other"));
     }
     this.channelParts.Union(other.channelParts);
     if (other.actionParts != null)
     {
         foreach (string str in other.actionParts.Keys)
         {
             MessagePartSpecification specification = new MessagePartSpecification();
             specification.Union(other.actionParts[str]);
             this.actionParts[str] = specification;
         }
     }
 }
예제 #10
0
		public void Union ()
		{
			XmlQualifiedName q1, q2, q3;
			q1 = new XmlQualifiedName ("foo");
			q2 = new XmlQualifiedName ("bar");
			q3 = new XmlQualifiedName ("baz");
			MessagePartSpecification p1 =
				new MessagePartSpecification (false, new XmlQualifiedName [] {q1, q2});
			MessagePartSpecification p2 =
				new MessagePartSpecification (true, new XmlQualifiedName [] {q3, q2});
			p1.Union (p2);
			Assert.IsTrue (p1.IsBodyIncluded, "#1");
			// Sigh. It does not exclude duplicates.
			Assert.AreEqual (4, p1.HeaderTypes.Count, "#1-2");
			Assert.IsTrue (p1.HeaderTypes.Contains (q1), "#2");
			Assert.IsTrue (p1.HeaderTypes.Contains (q2), "#3");
			Assert.IsTrue (p1.HeaderTypes.Contains (q3), "#4");
		}
        public virtual XmlElement CreateWsspBootstrapPolicyAssertion(MetadataExporter exporter, SecurityBindingElement bootstrapSecurity)
        {
            if (bootstrapSecurity == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bootstrapBinding");

            WSSecurityPolicy sp = WSSecurityPolicy.GetSecurityPolicyDriver(bootstrapSecurity.MessageSecurityVersion);

            // create complete bootstrap binding

            CustomBinding bootstrapBinding = new CustomBinding(bootstrapSecurity);
            if (exporter.State.ContainsKey(SecurityPolicyStrings.SecureConversationBootstrapBindingElementsBelowSecurityKey))
            {
                BindingElementCollection bindingElementsBelowSecurity = exporter.State[SecurityPolicyStrings.SecureConversationBootstrapBindingElementsBelowSecurityKey] as BindingElementCollection;
                if (bindingElementsBelowSecurity != null)
                {
                    foreach (BindingElement be in bindingElementsBelowSecurity)
                    {
                        bootstrapBinding.Elements.Add(be);
                    }
                }
            }

            // generate policy for the "how" of security 

            ServiceEndpoint bootstrapEndpoint = new ServiceEndpoint(NullContract);
            bootstrapEndpoint.Binding = bootstrapBinding;
            PolicyConversionContext policyContext = exporter.ExportPolicy(bootstrapEndpoint);

            // generate policy for the "what" of security (protection assertions)

            // hard-coded requirements in V1: sign and encrypt RST and RSTR body
            ChannelProtectionRequirements bootstrapProtection = new ChannelProtectionRequirements();
            bootstrapProtection.IncomingEncryptionParts.AddParts(new MessagePartSpecification(true));
            bootstrapProtection.OutgoingEncryptionParts.AddParts(new MessagePartSpecification(true));
            bootstrapProtection.IncomingSignatureParts.AddParts(new MessagePartSpecification(true));
            bootstrapProtection.OutgoingSignatureParts.AddParts(new MessagePartSpecification(true));

            // add boostrap binding protection requirements (e.g. addressing headers)
            ChannelProtectionRequirements cpr = bootstrapBinding.GetProperty<ChannelProtectionRequirements>(new BindingParameterCollection());
            if (cpr != null)
            {
                bootstrapProtection.Add(cpr);
            }

            // extract channel-scope protection requirements and union them across request and response
            MessagePartSpecification encryption = new MessagePartSpecification();
            encryption.Union(bootstrapProtection.IncomingEncryptionParts.ChannelParts);
            encryption.Union(bootstrapProtection.OutgoingEncryptionParts.ChannelParts);
            encryption.MakeReadOnly();
            MessagePartSpecification signature = new MessagePartSpecification();
            signature.Union(bootstrapProtection.IncomingSignatureParts.ChannelParts);
            signature.Union(bootstrapProtection.OutgoingSignatureParts.ChannelParts);
            signature.MakeReadOnly();

            // create final boostrap policy assertion

            XmlElement nestedPolicy = CreateWspPolicyWrapper(
                    exporter,
                    sp.CreateWsspSignedPartsAssertion(signature),
                    sp.CreateWsspEncryptedPartsAssertion(encryption));
            foreach (XmlElement e in sp.FilterWsspPolicyAssertions(policyContext.GetBindingAssertions()))
            {
                nestedPolicy.AppendChild(e);
            }
            XmlElement result = CreateWsspAssertion(BootstrapPolicyName);
            result.AppendChild(nestedPolicy);

            return result;
        }
 public void MakeReadOnly()
 {
     if (!_isReadOnly)
     {
         _readOnlyNormalizedActionParts = new Dictionary<string, MessagePartSpecification>();
         foreach (string action in _actionParts.Keys)
         {
             MessagePartSpecification p = new MessagePartSpecification();
             p.Union(_actionParts[action]);
             p.Union(_channelParts);
             p.MakeReadOnly();
             _readOnlyNormalizedActionParts[action] = p;
         }
         _isReadOnly = true;
     }
 }
        public bool TryGetParts(string action, bool excludeChannelScope, out MessagePartSpecification parts)
        {
            if (action == null)
                action = MessageHeaders.WildcardAction;
            parts = null;

            if (_isReadOnly)
            {
                if (_readOnlyNormalizedActionParts.ContainsKey(action))
                    if (excludeChannelScope)
                        parts = _actionParts[action];
                    else
                        parts = _readOnlyNormalizedActionParts[action];
            }
            else if (_actionParts.ContainsKey(action))
            {
                MessagePartSpecification p = new MessagePartSpecification();
                p.Union(_actionParts[action]);
                if (!excludeChannelScope)
                    p.Union(_channelParts);
                parts = p;
            }

            return parts != null;
        }
 public bool TryGetParts(string action, bool excludeChannelScope, out MessagePartSpecification parts)
 {
     if (action == null)
     {
         action = "*";
     }
     parts = null;
     if (this.isReadOnly)
     {
         if (this.readOnlyNormalizedActionParts.ContainsKey(action))
         {
             if (excludeChannelScope)
             {
                 parts = this.actionParts[action];
             }
             else
             {
                 parts = this.readOnlyNormalizedActionParts[action];
             }
         }
     }
     else if (this.actionParts.ContainsKey(action))
     {
         MessagePartSpecification specification = new MessagePartSpecification();
         specification.Union(this.actionParts[action]);
         if (!excludeChannelScope)
         {
             specification.Union(this.channelParts);
         }
         parts = specification;
     }
     return (parts != null);
 }
 public void MakeReadOnly()
 {
     if (!this.isReadOnly)
     {
         this.readOnlyNormalizedActionParts = new Dictionary<string, MessagePartSpecification>();
         foreach (string str in this.actionParts.Keys)
         {
             MessagePartSpecification specification = new MessagePartSpecification();
             specification.Union(this.actionParts[str]);
             specification.Union(this.channelParts);
             specification.MakeReadOnly();
             this.readOnlyNormalizedActionParts[str] = specification;
         }
         this.isReadOnly = true;
     }
 }
 public virtual XmlElement CreateWsspBootstrapPolicyAssertion(MetadataExporter exporter, SecurityBindingElement bootstrapSecurity)
 {
     if (bootstrapSecurity == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bootstrapBinding");
     }
     WSSecurityPolicy securityPolicyDriver = GetSecurityPolicyDriver(bootstrapSecurity.MessageSecurityVersion);
     CustomBinding binding = new CustomBinding(new BindingElement[] { bootstrapSecurity });
     if (exporter.State.ContainsKey("SecureConversationBootstrapBindingElementsBelowSecurityKey"))
     {
         BindingElementCollection elements = exporter.State["SecureConversationBootstrapBindingElementsBelowSecurityKey"] as BindingElementCollection;
         if (elements != null)
         {
             foreach (BindingElement element in elements)
             {
                 binding.Elements.Add(element);
             }
         }
     }
     ServiceEndpoint endpoint = new ServiceEndpoint(NullContract) {
         Binding = binding
     };
     PolicyConversionContext context = exporter.ExportPolicy(endpoint);
     ChannelProtectionRequirements requirements = new ChannelProtectionRequirements();
     requirements.IncomingEncryptionParts.AddParts(new MessagePartSpecification(true));
     requirements.OutgoingEncryptionParts.AddParts(new MessagePartSpecification(true));
     requirements.IncomingSignatureParts.AddParts(new MessagePartSpecification(true));
     requirements.OutgoingSignatureParts.AddParts(new MessagePartSpecification(true));
     ChannelProtectionRequirements property = binding.GetProperty<ChannelProtectionRequirements>(new BindingParameterCollection());
     if (property != null)
     {
         requirements.Add(property);
     }
     MessagePartSpecification parts = new MessagePartSpecification();
     parts.Union(requirements.IncomingEncryptionParts.ChannelParts);
     parts.Union(requirements.OutgoingEncryptionParts.ChannelParts);
     parts.MakeReadOnly();
     MessagePartSpecification specification2 = new MessagePartSpecification();
     specification2.Union(requirements.IncomingSignatureParts.ChannelParts);
     specification2.Union(requirements.OutgoingSignatureParts.ChannelParts);
     specification2.MakeReadOnly();
     XmlElement newChild = this.CreateWspPolicyWrapper(exporter, new XmlElement[] { securityPolicyDriver.CreateWsspSignedPartsAssertion(specification2), securityPolicyDriver.CreateWsspEncryptedPartsAssertion(parts) });
     foreach (XmlElement element3 in securityPolicyDriver.FilterWsspPolicyAssertions(context.GetBindingAssertions()))
     {
         newChild.AppendChild(element3);
     }
     XmlElement element4 = this.CreateWsspAssertion("BootstrapPolicy");
     element4.AppendChild(newChild);
     return element4;
 }