internal static void WriteAckRanges(XmlDictionaryWriter writer, ReliableMessagingVersion reliableMessagingVersion, UniqueId sequenceId, SequenceRangeCollection ranges)
 {
     WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary;
     XmlDictionaryString namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);
     writer.WriteStartElement(dictionary.Identifier, namespaceUri);
     writer.WriteValue(sequenceId);
     writer.WriteEndElement();
     if (ranges.Count == 0)
     {
         if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005)
         {
             ranges = ranges.MergeWith((long) 0L);
         }
         else if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
         {
             writer.WriteStartElement(DXD.Wsrm11Dictionary.None, namespaceUri);
             writer.WriteEndElement();
         }
     }
     for (int i = 0; i < ranges.Count; i++)
     {
         writer.WriteStartElement(dictionary.AcknowledgementRange, namespaceUri);
         writer.WriteStartAttribute(dictionary.Lower, null);
         SequenceRange range = ranges[i];
         writer.WriteValue(range.Lower);
         writer.WriteEndAttribute();
         writer.WriteStartAttribute(dictionary.Upper, null);
         SequenceRange range2 = ranges[i];
         writer.WriteValue(range2.Upper);
         writer.WriteEndAttribute();
         writer.WriteEndElement();
     }
 }
 public void WriteTo(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString ns, XmlDictionaryString valueTypeLocalName, XmlDictionaryString valueTypeNs)
 {
     writer.WriteStartElement(prefix, localName, ns);
     writer.WriteStartAttribute(valueTypeLocalName, valueTypeNs);
     if (valueTypeUriDictionaryString != null)
         writer.WriteString(valueTypeUriDictionaryString);
     else
         writer.WriteString(valueTypeUri);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(XD.SecurityJan2004Dictionary.EncodingType, null);
     writer.WriteString(XD.SecurityJan2004Dictionary.EncodingTypeValueBase64Binary);
     writer.WriteEndAttribute();
     writer.WriteBase64(this.negotiationData, 0, this.negotiationData.Length);
     writer.WriteEndElement();
 }
 protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteStartElement(this.Name, this.Namespace);
     writer.WriteXmlnsAttribute(null, _notUnderstoodNs);
     writer.WriteStartAttribute(Message12Strings.QName);
     writer.WriteQualifiedName(_notUnderstoodName, _notUnderstoodNs);
     writer.WriteEndAttribute();
 }
 protected override void OnWriteAddressHeaderContents(XmlDictionaryWriter writer)
 {
     if (this.protocol != ControlProtocol.None)
     {
         writer.WriteStartAttribute(XD.DotNetAtomicTransactionExternalDictionary.Protocol, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
         writer.WriteValue((int) this.protocol);
         writer.WriteEndAttribute();
     }
     writer.WriteValue(this.enlistment);
 }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(this.prefix, this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     if (this.algorithmDictionaryString != null)
     {
         writer.WriteString(this.algorithmDictionaryString);
     }
     else
     {
         writer.WriteString(this.algorithm);
     }
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
 public void WriteTo(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement(XmlEncryptionStrings.Prefix, ElementName, XD.XmlEncryptionDictionary.Namespace);
     if (this.algorithmDictionaryString != null)
     {
         writer.WriteStartAttribute(XD.XmlSignatureDictionary.Algorithm, null);
         writer.WriteString(this.algorithmDictionaryString);
         writer.WriteEndAttribute();
     }
     else
     {
         writer.WriteAttributeString(XD.XmlSignatureDictionary.Algorithm, null, this.algorithm);
     }
     if (this.algorithm == XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value)
     {
         writer.WriteStartElement(XmlSignatureStrings.Prefix, XD.XmlSignatureDictionary.DigestMethod, XD.XmlSignatureDictionary.Namespace);
         writer.WriteStartAttribute(XD.XmlSignatureDictionary.Algorithm, null);
         writer.WriteString(XD.SecurityAlgorithmDictionary.Sha1Digest);
         writer.WriteEndAttribute();
         writer.WriteEndElement();
     }
     writer.WriteEndElement(); // EncryptionMethod
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Attribute, samlDictionary.Namespace);
     writer.WriteStartAttribute(samlDictionary.AttributeName, null);
     writer.WriteString(this.name);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(samlDictionary.AttributeNamespace, null);
     writer.WriteString(this.nameSpace);
     writer.WriteEndAttribute();
     for (int i = 0; i < this.attributeValues.Count; i++)
     {
         if (this.attributeValues[i] == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.IdentityModel.SR.GetString("SAMLAttributeValueCannotBeNull"));
         }
         writer.WriteElementString(samlDictionary.PreferredPrefix.Value, samlDictionary.AttributeValue, samlDictionary.Namespace, this.attributeValues[i]);
     }
     writer.WriteEndElement();
 }
        public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
        {
            string prefix = XmlSignatureStrings.Prefix;
            XmlDictionaryString ns = dictionaryManager.XmlSignatureDictionary.Namespace;

            writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, ns);
            if (this.Id != null)
            {
                writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.Id);
            }
            WriteCanonicalizationMethod(writer, dictionaryManager);
            WriteSignatureMethod(writer, dictionaryManager);
            for (int i = 0; i < this.count; i++)
            {
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, ns);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null);
                writer.WriteString("#");
                writer.WriteString(this.references[i].id);
                writer.WriteEndAttribute();

                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, ns);
                if (this.addEnvelopedSignatureTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); // Transform
                }

                if (this.references[i].useStrTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(SecurityAlgorithms.StrTransform);
                    writer.WriteEndAttribute();
                    writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);  //<wsse:TransformationParameters>
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); //CanonicalizationMethod 
                    writer.WriteEndElement(); // TransformationParameters
                    writer.WriteEndElement(); // Transform
                }
                else
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); // Transform
                }

                writer.WriteEndElement(); // Transforms

                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, ns);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                if (this.digestMethodDictionaryString != null)
                {
                    writer.WriteString(this.digestMethodDictionaryString);
                }
                else
                {
                    writer.WriteString(this.digestMethod);
                }
                writer.WriteEndAttribute();
                writer.WriteEndElement(); // DigestMethod

                byte[] digest = this.references[i].digest;
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, ns);
                writer.WriteBase64(digest, 0, digest.Length);
                writer.WriteEndElement(); // DigestValue

                writer.WriteEndElement(); // Reference
            }
            writer.WriteEndElement(); // SignedInfo
        }
        public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
        {
            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));

            if (samlSerializer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Conditions, dictionary.Namespace);

            if (this.notBefore != SecurityUtils.MinUtcDateTime)
            {
                writer.WriteStartAttribute(dictionary.NotBefore, null);
                writer.WriteString(this.notBefore.ToString(SamlConstants.GeneratedDateTimeFormat, DateTimeFormatInfo.InvariantInfo));
                writer.WriteEndAttribute();
            }

            if (this.notOnOrAfter != SecurityUtils.MaxUtcDateTime)
            {
                writer.WriteStartAttribute(dictionary.NotOnOrAfter, null);
                writer.WriteString(this.notOnOrAfter.ToString(SamlConstants.GeneratedDateTimeFormat, DateTimeFormatInfo.InvariantInfo));
                writer.WriteEndAttribute();
            }

            for (int i = 0; i < this.conditions.Count; i++)
            {
                this.conditions[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
            }

            writer.WriteEndElement();
        }
 public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     writer.WriteString(this.Algorithm);
     writer.WriteEndAttribute();
     this.transformationParameters.WriteTo(writer, dictionaryManager);
     writer.WriteEndElement(); // Transform
 }
 static public void WriteAttributeStringAsUniqueId(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString ns, UniqueId id)
 {
     writer.WriteStartAttribute(prefix, localName, ns);
     writer.WriteValue(id);
     writer.WriteEndAttribute();
 }
 public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AuthorizationDecisionStatement, samlDictionary.Namespace);
     writer.WriteStartAttribute(samlDictionary.Decision, null);
     writer.WriteString(this.accessDecision.ToString());
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(samlDictionary.Resource, null);
     writer.WriteString(this.resource);
     writer.WriteEndAttribute();
     base.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer);
     foreach (SamlAction action in this.actions)
     {
         action.WriteXml(writer, samlSerializer, keyInfoSerializer);
     }
     if (this.evidence != null)
     {
         this.evidence.WriteXml(writer, samlSerializer, keyInfoSerializer);
     }
     writer.WriteEndElement();
 }
Exemple #13
0
 public override void WriteEndAttribute()
 {
     writer.WriteEndAttribute();
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     try
     {
         writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Assertion, samlDictionary.Namespace);
         writer.WriteStartAttribute(samlDictionary.MajorVersion, null);
         writer.WriteValue(SamlConstants.MajorVersionValue);
         writer.WriteEndAttribute();
         writer.WriteStartAttribute(samlDictionary.MinorVersion, null);
         writer.WriteValue(SamlConstants.MinorVersionValue);
         writer.WriteEndAttribute();
         writer.WriteStartAttribute(samlDictionary.AssertionId, null);
         writer.WriteString(this.assertionId);
         writer.WriteEndAttribute();
         writer.WriteStartAttribute(samlDictionary.Issuer, null);
         writer.WriteString(this.issuer);
         writer.WriteEndAttribute();
         writer.WriteStartAttribute(samlDictionary.IssueInstant, null);
         writer.WriteString(this.issueInstant.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture));
         writer.WriteEndAttribute();
         if (this.conditions != null)
         {
             this.conditions.WriteXml(writer, samlSerializer, keyInfoSerializer);
         }
         if (this.advice != null)
         {
             this.advice.WriteXml(writer, samlSerializer, keyInfoSerializer);
         }
         for (int i = 0; i < this.statements.Count; i++)
         {
             this.statements[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
         }
         writer.WriteEndElement();
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("SAMLTokenNotSerialized"), exception));
     }
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AuthorityBinding, samlDictionary.Namespace);
     string prefix = null;
     if (!string.IsNullOrEmpty(this.authorityKind.Namespace))
     {
         writer.WriteAttributeString(string.Empty, samlDictionary.NamespaceAttributePrefix.Value, null, this.authorityKind.Namespace);
         prefix = writer.LookupPrefix(this.authorityKind.Namespace);
     }
     writer.WriteStartAttribute(samlDictionary.AuthorityKind, null);
     if (string.IsNullOrEmpty(prefix))
     {
         writer.WriteString(this.authorityKind.Name);
     }
     else
     {
         writer.WriteString(prefix + ":" + this.authorityKind.Name);
     }
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(samlDictionary.Location, null);
     writer.WriteString(this.location);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(samlDictionary.Binding, null);
     writer.WriteString(this.binding);
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
        public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
        {
            CheckObjectValidity();

            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));

            if (samlSerializer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AuthorityBinding, dictionary.Namespace);

            string prefix = null;
            if (!string.IsNullOrEmpty(this.authorityKind.Namespace))
            {
                writer.WriteAttributeString(String.Empty, dictionary.NamespaceAttributePrefix.Value, null, this.authorityKind.Namespace);
                prefix = writer.LookupPrefix(this.authorityKind.Namespace);
            }

            writer.WriteStartAttribute(dictionary.AuthorityKind, null);
            if (string.IsNullOrEmpty(prefix))
                writer.WriteString(this.authorityKind.Name);
            else
                writer.WriteString(prefix + ":" + this.authorityKind.Name);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute(dictionary.Location, null);
            writer.WriteString(this.location);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute(dictionary.Binding, null);
            writer.WriteString(this.binding);
            writer.WriteEndAttribute();

            writer.WriteEndElement();
        }
 public void WriteTo(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("e", ElementName, System.ServiceModel.XD.XmlEncryptionDictionary.Namespace);
     if (this.algorithmDictionaryString != null)
     {
         writer.WriteStartAttribute(System.ServiceModel.XD.XmlSignatureDictionary.Algorithm, null);
         writer.WriteString(this.algorithmDictionaryString);
         writer.WriteEndAttribute();
     }
     else
     {
         writer.WriteAttributeString(System.ServiceModel.XD.XmlSignatureDictionary.Algorithm, null, this.algorithm);
     }
     if (this.algorithm == System.ServiceModel.XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value)
     {
         writer.WriteStartElement("", System.ServiceModel.XD.XmlSignatureDictionary.DigestMethod, System.ServiceModel.XD.XmlSignatureDictionary.Namespace);
         writer.WriteStartAttribute(System.ServiceModel.XD.XmlSignatureDictionary.Algorithm, null);
         writer.WriteString(System.ServiceModel.XD.SecurityAlgorithmDictionary.Sha1Digest);
         writer.WriteEndAttribute();
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
 public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     XmlDictionaryString localName = this.isCanonicalizationMethod ? dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform;
     XmlDictionaryString str2 = this.includeComments ? dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14nWithComments : dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n;
     writer.WriteStartElement(this.prefix, localName, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     if (str2 != null)
     {
         writer.WriteString(str2);
     }
     else
     {
         writer.WriteString(str2.Value);
     }
     writer.WriteEndAttribute();
     if (this.InclusiveNamespacesPrefixList != null)
     {
         writer.WriteStartElement(this.inclusiveListElementPrefix, dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace);
         writer.WriteAttributeString(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null, this.InclusiveNamespacesPrefixList);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Exemple #19
0
		public override void WriteStartObject (
			XmlDictionaryWriter writer, object graph)
		{
			Type rootType = type;
			
			if (root_name.Value == "")
				throw new InvalidDataContractException ("Type '" + type.ToString () +
					"' cannot have a DataContract attribute Name set to null or empty string.");


			if (graph == null) {
				if (names_filled)
					writer.WriteStartElement (root_name.Value, root_ns.Value);
				else
					writer.WriteStartElement (root_name, root_ns);
				writer.WriteAttributeString ("i", "nil", XmlSchema.InstanceNamespace, "true");
				return;
			}

			QName instName = null;
			QName root_qname = known_types.GetQName (rootType);
			QName graph_qname = known_types.GetQName (graph.GetType ());

			known_types.Add (graph.GetType ());

			if (names_filled)
				writer.WriteStartElement (root_name.Value, root_ns.Value);
			else
				writer.WriteStartElement (root_name, root_ns);
			if (root_ns.Value != root_qname.Namespace)
				if (root_qname.Namespace != KnownTypeCollection.MSSimpleNamespace)
					writer.WriteXmlnsAttribute (null, root_qname.Namespace);

			if (root_qname == graph_qname) {
				if (root_qname.Namespace != KnownTypeCollection.MSSimpleNamespace &&
					!rootType.IsEnum)
					//FIXME: Hack, when should the "i:type" be written?
					//Not used in case of enums
					writer.WriteXmlnsAttribute ("i", XmlSchema.InstanceNamespace);

				return;
			}

			/* Different names */
			known_types.Add (rootType);
			
			instName = KnownTypeCollection.GetPredefinedTypeName (graph.GetType ());
			if (instName == QName.Empty)
				/* Not a primitive type */
				instName = graph_qname;
			else
				/* FIXME: Hack, .. see test WriteObject7 () */
				instName = new QName (instName.Name, XmlSchema.Namespace);

			// output xsi:type as rootType is not equivalent to the graph's type.
			writer.WriteStartAttribute ("i", "type", XmlSchema.InstanceNamespace);
			writer.WriteQualifiedName (instName.Name, instName.Namespace);
			writer.WriteEndAttribute ();
		}
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Action, samlDictionary.Namespace);
     if (this.ns != null)
     {
         writer.WriteStartAttribute(samlDictionary.ActionNamespaceAttribute, null);
         writer.WriteString(this.ns);
         writer.WriteEndAttribute();
     }
     writer.WriteString(this.action);
     writer.WriteEndElement();
 }
 private void SerializeParameter(XmlDictionaryWriter writer, PartInfo part, object graph)
 {
     writer.WriteStartElement(part.DictionaryName, part.DictionaryNamespace);
     if (graph == null)
     {
         writer.WriteStartAttribute(_xsiNilLocalName, _xsiNilNamespace);
         writer.WriteValue(true);
         writer.WriteEndAttribute();
     }
     else
         part.WriteValue(writer, graph);
     writer.WriteEndElement();
 }
        public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
        {
            CheckObjectValidity();

            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));

            if (samlSerializer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AuthenticationStatement, dictionary.Namespace);

            writer.WriteStartAttribute(dictionary.AuthenticationMethod, null);
            writer.WriteString(this.authenticationMethod);
            writer.WriteEndAttribute();
            writer.WriteStartAttribute(dictionary.AuthenticationInstant, null);
            writer.WriteString(this.authenticationInstant.ToString(SamlConstants.GeneratedDateTimeFormat, CultureInfo.InvariantCulture));
            writer.WriteEndAttribute();

            this.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer);

            if ((this.ipAddress != null) || (this.dnsAddress != null))
            {
                writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.SubjectLocality, dictionary.Namespace);

                if (this.ipAddress != null)
                {
                    writer.WriteStartAttribute(dictionary.SubjectLocalityIPAddress, null);
                    writer.WriteString(this.ipAddress);
                    writer.WriteEndAttribute();
                }

                if (this.dnsAddress != null)
                {
                    writer.WriteStartAttribute(dictionary.SubjectLocalityDNSAddress, null);
                    writer.WriteString(this.dnsAddress);
                    writer.WriteEndAttribute();
                }

                writer.WriteEndElement();
            }

            for (int i = 0; i < this.authorityBindings.Count; i++)
            {
                this.authorityBindings[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
            }

            writer.WriteEndElement();
        }
        public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
        {
            CheckObjectValidity();

            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");

            if (samlSerializer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            try
            {
                writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Assertion, dictionary.Namespace);

                writer.WriteStartAttribute(dictionary.MajorVersion, null);
                writer.WriteValue(SamlConstants.MajorVersionValue);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.MinorVersion, null);
                writer.WriteValue(SamlConstants.MinorVersionValue);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.AssertionId, null);
                writer.WriteString(this.assertionId);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.Issuer, null);
                writer.WriteString(this.issuer);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.IssueInstant, null);
                writer.WriteString(this.issueInstant.ToString(SamlConstants.GeneratedDateTimeFormat, CultureInfo.InvariantCulture));
                writer.WriteEndAttribute();

                // Write out conditions
                if (this.conditions != null)
                {
                    this.conditions.WriteXml(writer, samlSerializer, keyInfoSerializer);
                }

                // Write out advice if there is one
                if (this.advice != null)
                {
                    this.advice.WriteXml(writer, samlSerializer, keyInfoSerializer);
                }

                for (int i = 0; i < this.statements.Count; i++)
                {
                    this.statements[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
                }

                writer.WriteEndElement();
            }
            catch (Exception e)
            {
                // Always immediately rethrow fatal exceptions.
                if (Fx.IsFatal(e)) throw;

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SAMLTokenNotSerialized), e));
            }
        }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);  //<wsse:TransformationParameters>
     writer.WriteStartElement(dictionaryManager.XmlSignatureDictionary.Prefix.Value, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
     writer.WriteEndAttribute();
     writer.WriteEndElement(); // CanonicalizationMethod 
     writer.WriteEndElement(); // TransformationParameters
 }
		public override void WriteXml (XmlDictionaryWriter writer,
			SamlSerializer samlSerializer, 
			SecurityTokenSerializer keyInfoSerializer)
		{
			if (writer == null)
				throw new ArgumentNullException ("writer");
			if (samlSerializer == null)
				throw new ArgumentNullException ("samlSerializer");
			if (SamlActions.Count == 0)
				throw new SecurityTokenException ("SAML AuthorizationDecisionStatement must contain at least one Action.");

			if (SamlSubject == null)
				throw new SecurityTokenException ("SAML Subject must be set to SAML AuthorizationDecisionStatement before being written.");
			if (Resource == null || Resource.Length == 0)
				throw new SecurityTokenException ("non-zero string must be set to Resource on SAML AuthorizationDecisionStatement.");

			writer.WriteStartElement ("saml", "AuthorizationDecisionStatement", SamlConstants.Namespace);

			writer.WriteStartAttribute ("Decision");
			switch (AccessDecision) {
			case SamlAccessDecision.Permit:
				writer.WriteString ("Permit");
				break;
			case SamlAccessDecision.Deny:
				writer.WriteString ("Deny");
				break;
			case SamlAccessDecision.Indeterminate:
				writer.WriteString ("Indeterminate");
				break;
			default:
				throw new ArgumentOutOfRangeException ("AccessDecision value is wrong.");
			}
			writer.WriteEndAttribute ();

			writer.WriteAttributeString ("Resource", Resource);
			SamlSubject.WriteXml (writer, samlSerializer, keyInfoSerializer);
			foreach (SamlAction action in SamlActions)
				action.WriteXml (writer, samlSerializer, keyInfoSerializer);
			if (Evidence != null)
				Evidence.WriteXml (writer, samlSerializer, keyInfoSerializer);

			writer.WriteEndElement ();
		}
Exemple #26
0
 internal override void WriteSignatureConfirmation(XmlDictionaryWriter writer, string id, byte[] signature)
 {
     if (id == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("id");
     }
     if (signature == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("signature");
     }
     writer.WriteStartElement(XD.SecurityXXX2005Dictionary.Prefix.Value, XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace);
     writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, id);
     writer.WriteStartAttribute(XD.SecurityXXX2005Dictionary.ValueAttribute, null);
     writer.WriteBase64(signature, 0, signature.Length);
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
 public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AuthenticationStatement, samlDictionary.Namespace);
     writer.WriteStartAttribute(samlDictionary.AuthenticationMethod, null);
     writer.WriteString(this.authenticationMethod);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(samlDictionary.AuthenticationInstant, null);
     writer.WriteString(this.authenticationInstant.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture));
     writer.WriteEndAttribute();
     base.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer);
     if ((this.ipAddress != null) || (this.dnsAddress != null))
     {
         writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.SubjectLocality, samlDictionary.Namespace);
         if (this.ipAddress != null)
         {
             writer.WriteStartAttribute(samlDictionary.SubjectLocalityIPAddress, null);
             writer.WriteString(this.ipAddress);
             writer.WriteEndAttribute();
         }
         if (this.dnsAddress != null)
         {
             writer.WriteStartAttribute(samlDictionary.SubjectLocalityDNSAddress, null);
             writer.WriteString(this.dnsAddress);
             writer.WriteEndAttribute();
         }
         writer.WriteEndElement();
     }
     for (int i = 0; i < this.authorityBindings.Count; i++)
     {
         this.authorityBindings[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
     }
     writer.WriteEndElement();
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Subject, samlDictionary.Namespace);
     if (this.name != null)
     {
         writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.NameIdentifier, samlDictionary.Namespace);
         if (this.nameFormat != null)
         {
             writer.WriteStartAttribute(samlDictionary.NameIdentifierFormat, null);
             writer.WriteString(this.nameFormat);
             writer.WriteEndAttribute();
         }
         if (this.nameQualifier != null)
         {
             writer.WriteStartAttribute(samlDictionary.NameIdentifierNameQualifier, null);
             writer.WriteString(this.nameQualifier);
             writer.WriteEndAttribute();
         }
         writer.WriteString(this.name);
         writer.WriteEndElement();
     }
     if (this.confirmationMethods.Count > 0)
     {
         writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.SubjectConfirmation, samlDictionary.Namespace);
         foreach (string str in this.confirmationMethods)
         {
             writer.WriteElementString(samlDictionary.SubjectConfirmationMethod, samlDictionary.Namespace, str);
         }
         if (!string.IsNullOrEmpty(this.confirmationData))
         {
             writer.WriteElementString(samlDictionary.SubjectConfirmationData, samlDictionary.Namespace, this.confirmationData);
         }
         if (this.securityKeyIdentifier != null)
         {
             SamlSerializer.WriteSecurityKeyIdentifier(XmlDictionaryWriter.CreateDictionaryWriter(writer), this.securityKeyIdentifier, keyInfoSerializer);
         }
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
        public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
        {
            CheckObjectValidity();

            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));

            if (samlSerializer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Attribute, dictionary.Namespace);

            writer.WriteStartAttribute(dictionary.AttributeName, null);
            writer.WriteString(this.name);
            writer.WriteEndAttribute();
            writer.WriteStartAttribute(dictionary.AttributeNamespace, null);
            writer.WriteString(this.nameSpace);
            writer.WriteEndAttribute();

            for (int i = 0; i < this.attributeValues.Count; i++)
            {
                if (this.attributeValues[i] == null)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLAttributeValueCannotBeNull));

                writer.WriteElementString(dictionary.PreferredPrefix.Value, dictionary.AttributeValue, dictionary.Namespace, this.attributeValues[i]);
            }

            writer.WriteEndElement();
        }
 public static void WriteTo(XmlDictionaryWriter writer, string referredId)
 {
     writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, ElementName, NamespaceUri);
     writer.WriteStartAttribute(ReferenceList.UriAttribute, null);
     writer.WriteString("#");
     writer.WriteString(referredId);
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Conditions, samlDictionary.Namespace);
     if (this.notBefore != System.IdentityModel.SecurityUtils.MinUtcDateTime)
     {
         writer.WriteStartAttribute(samlDictionary.NotBefore, null);
         writer.WriteString(this.notBefore.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", DateTimeFormatInfo.InvariantInfo));
         writer.WriteEndAttribute();
     }
     if (this.notOnOrAfter != System.IdentityModel.SecurityUtils.MaxUtcDateTime)
     {
         writer.WriteStartAttribute(samlDictionary.NotOnOrAfter, null);
         writer.WriteString(this.notOnOrAfter.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", DateTimeFormatInfo.InvariantInfo));
         writer.WriteEndAttribute();
     }
     for (int i = 0; i < this.conditions.Count; i++)
     {
         this.conditions[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
     }
     writer.WriteEndElement();
 }