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();
        }
        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();
        }
        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();
        }
Beispiel #4
0
        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 WriteRootAsObject()
 {
     w.WriteStartElement("root");
     w.WriteStartAttribute("type");
     w.WriteString("object");
     w.WriteEndAttribute();
     w.Close();
     Assert.AreEqual("{}", ResultString);
 }
        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 override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
        {
            string prefix = "";
            XmlDictionaryString namespaceUri = dictionaryManager.XmlSignatureDictionary.Namespace;

            writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, namespaceUri);
            if (base.Id != null)
            {
                writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, base.Id);
            }
            base.WriteCanonicalizationMethod(writer, dictionaryManager);
            base.WriteSignatureMethod(writer, dictionaryManager);
            for (int i = 0; i < this.count; i++)
            {
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, namespaceUri);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null);
                writer.WriteString("#");
                writer.WriteString(this.references[i].id);
                writer.WriteEndAttribute();
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, namespaceUri);
                if (this.addEnvelopedSignatureTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement();
                }
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                writer.WriteEndAttribute();
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, namespaceUri);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                if (this.digestMethodDictionaryString != null)
                {
                    writer.WriteString(this.digestMethodDictionaryString);
                }
                else
                {
                    writer.WriteString(this.digestMethod);
                }
                writer.WriteEndAttribute();
                writer.WriteEndElement();
                byte[] digest = this.references[i].digest;
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, namespaceUri);
                writer.WriteBase64(digest, 0, digest.Length);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
        }
        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));
            }
        }
Beispiel #9
0
        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 void UseCase2()
        {
            XmlDictionary       dic   = new XmlDictionary();
            MemoryStream        ms    = new MemoryStream();
            XmlDictionaryWriter w     = XmlDictionaryWriter.CreateBinaryWriter(ms, dic, null);
            XmlDictionaryString empty = dic.Add(String.Empty);

            // empty ns
            w.WriteStartElement(dic.Add("FOO"), empty);
            // non-dic string
            w.WriteStartElement("BAR");
            // second time ns
            w.WriteStartElement(dic.Add("FOO"), empty);
            // first time dic string but prior non-dic name existed
            w.WriteStartElement(dic.Add("BAR"), empty);
            w.WriteEndElement();
            w.WriteEndElement();
            w.WriteEndElement();
            // dicstr w/ ns with empty prefix
            w.WriteStartElement(dic.Add("BAR"), dic.Add("urn:bar"));
            // with prefix
            w.WriteStartElement("ppp", dic.Add("BAR"), dic.Add("urn:bar"));
            w.WriteChars(new char [] { 'x', 'y', 'z' }, 0, 3);
//			w.WriteString ("xyz"); // the same as WriteChars()
            w.WriteEndElement();
            w.WriteString("bbbb");
            w.WriteCData("ccc");
            w.WriteValue(new Guid("11112222333344445555666677778888"));
            w.WriteEndElement();
            w.WriteStartElement("FOO");
            w.WriteStartAttribute("AAA");
            w.WriteValue(new Guid("11112222333344445555666677778888"));
            w.WriteEndAttribute();
            w.WriteStartAttribute("BBB");
            w.WriteValue(TimeSpan.Zero);
            w.WriteEndAttribute();
            w.WriteStartAttribute("CC");
            w.WriteValue(new UniqueId("uuid-00000000-0000-0000-0000-000000000000-1"));
            w.WriteEndAttribute();
            w.WriteStartElement("XX");
            w.WriteValue(true);
            w.WriteValue(false);
            w.WriteEndElement();
            w.WriteStartElement("xx", "aaa", "urn:zzz");
            w.WriteEndElement();
            w.WriteEndElement();

            w.Close();

            Assert.AreEqual(usecase2_result, ms.ToArray());
        }
        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.Action, dictionary.Namespace);

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

            writer.WriteString(this.action);

            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();
        }
 protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteStartElement(Name, Namespace);
     writer.WriteXmlnsAttribute(null, notUnderstoodNs);
     writer.WriteStartAttribute(Message12Strings.QName);
     writer.WriteQualifiedName(notUnderstoodName, notUnderstoodNs);
     writer.WriteEndAttribute();
 }
 protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteStartElement(this.Name, this.Namespace);
     writer.WriteXmlnsAttribute(null, this.notUnderstoodNs);
     writer.WriteStartAttribute("qname");
     writer.WriteQualifiedName(this.notUnderstoodName, this.notUnderstoodNs);
     writer.WriteEndAttribute();
 }
 /// <summary>
 /// Closes the previous System.Xml.XmlWriter.WriteStartAttribute(System.String,System.String) call.
 /// </summary>
 public override void WriteEndAttribute()
 {
     _innerWriter.WriteEndAttribute();
     if (_tracingWriter != null)
     {
         _tracingWriter.WriteEndAttribute();
     }
 }
        public void UseCase1()
        {
            Console.WriteLine();

            MemoryStream        ms = new MemoryStream();
            XmlDictionaryWriter w  = XmlDictionaryWriter.CreateBinaryWriter(ms, null, null);

            w.WriteStartDocument(true);
            w.WriteStartElement("root");
            w.WriteAttributeString("a", "");
            w.WriteComment("");

            w.WriteWhitespace("     ");
            w.WriteStartElement("AAA", "urn:AAA");
            w.WriteEndElement();
            w.WriteStartElement("ePfix", "AAA", "urn:AAABBB");
            w.WriteEndElement();
            w.WriteStartElement("AAA");
            w.WriteCData("CCC\u3005\u4E00CCC");
            w.WriteString("AAA&AAA");
            w.WriteRaw("DDD&DDD");
            w.WriteCharEntity('\u4E01');
            w.WriteComment("COMMENT");
            w.WriteEndElement();
            w.WriteStartElement("AAA");
            w.WriteAttributeString("BBB", "bbb");
            // mhm, how namespace URIs are serialized then?
            w.WriteAttributeString("pfix", "BBB", "urn:bbb", "bbbbb");
            // 0x26-0x3F
            w.WriteAttributeString("CCC", "urn:ccc", "ccccc");
            w.WriteAttributeString("DDD", "urn:ddd", "ddddd");
            w.WriteAttributeString("CCC", "urn:ddd", "cdcdc");

            // XmlLang
            w.WriteXmlAttribute("lang", "ja");
            Assert.AreEqual("ja", w.XmlLang, "XmlLang");

            // XmlSpace
            w.WriteStartAttribute("xml", "space", "http://www.w3.org/XML/1998/namespace");
            w.WriteString("pre");
            w.WriteString("serve");
            w.WriteEndAttribute();
            Assert.AreEqual(XmlSpace.Preserve, w.XmlSpace, "XmlSpace");

            w.WriteAttributeString("xml", "base", "http://www.w3.org/XML/1998/namespace", "local:hogehoge");

            w.WriteString("CCC");
            w.WriteBase64(new byte [] { 0x20, 0x20, 0x20, 0xFF, 0x80, 0x30 }, 0, 6);
            w.WriteEndElement();
            // this WriteEndElement() should result in one more
            // 0x3C, but .net does not output it.
            w.WriteEndElement();
            w.WriteEndDocument();

            w.Close();

            Assert.AreEqual(usecase1_result, ms.ToArray());
        }
Beispiel #17
0
        public void Serialize(Type type, object graph)
        {
            if (graph == null)
            {
                writer.WriteAttributeString("nil", XmlSchema.InstanceNamespace, "true");
            }
            else
            {
                Type actualType = graph.GetType();

                SerializationMap map = types.FindUserMap(actualType);
                // For some collection types, the actual type does not matter. So get nominal serialization type instead.
                // (The code below also covers the lines above, but I don't remove above lines to avoid extra search cost.)
                if (map == null)
                {
                    actualType = types.GetSerializedType(actualType);
                    map        = types.FindUserMap(actualType);
                }
                // If it is still unknown, then register it.
                if (map == null)
                {
                    types.Add(actualType);
                    map = types.FindUserMap(actualType);
                }

                if (actualType != type && (map == null || map.OutputXsiType))
                {
                    QName  qname = types.GetXmlName(actualType);
                    string name  = qname.Name;
                    string ns    = qname.Namespace;
                    if (qname == QName.Empty)
                    {
                        name = XmlConvert.EncodeLocalName(actualType.Name);
                        ns   = KnownTypeCollection.DefaultClrNamespaceBase + actualType.Namespace;
                    }
                    else if (qname.Namespace == KnownTypeCollection.MSSimpleNamespace)
                    {
                        ns = XmlSchema.Namespace;
                    }
                    if (writer.LookupPrefix(ns) == null)                      // it goes first (extraneous, but it makes att order compatible)
                    {
                        writer.WriteXmlnsAttribute(null, ns);
                    }
                    writer.WriteStartAttribute("type", XmlSchema.InstanceNamespace);
                    writer.WriteQualifiedName(name, ns);
                    writer.WriteEndAttribute();
                }
                QName predef = KnownTypeCollection.GetPredefinedTypeName(actualType);
                if (predef != QName.Empty)
                {
                    SerializePrimitive(type, graph, predef);
                }
                else
                {
                    map.Serialize(graph, this);
                }
            }
        }
Beispiel #18
0
 public static void WriteTo(XmlDictionaryWriter writer, string referredId)
 {
     writer.WriteStartElement(System.IdentityModel.XD.XmlEncryptionDictionary.Prefix.Value, ReferenceList.DataReference.ElementName, ReferenceList.DataReference.NamespaceUri);
     writer.WriteStartAttribute(ReferenceList.UriAttribute, (XmlDictionaryString)null);
     writer.WriteString("#");
     writer.WriteString(referredId);
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
Beispiel #19
0
 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();
 }
Beispiel #20
0
 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
 }
Beispiel #21
0
        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();
        }
 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, 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(_negotiationData, 0, _negotiationData.Length);
     writer.WriteEndElement();
 }
Beispiel #24
0
 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 WriteEndAttribute()
 {
     if (_ignoreEndAttribute)
     {
         _ignoreEndAttribute = false;
     }
     else
     {
         _writer.WriteEndAttribute();
     }
 }
        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();
        }
Beispiel #27
0
 public void WriteTo(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("e", EncryptedType.EncryptionMethodElement.ElementName, System.IdentityModel.XD.XmlEncryptionDictionary.Namespace);
     if (this.algorithmDictionaryString != null)
     {
         writer.WriteStartAttribute(System.IdentityModel.XD.XmlSignatureDictionary.Algorithm, (XmlDictionaryString)null);
         writer.WriteString(this.algorithmDictionaryString);
         writer.WriteEndAttribute();
     }
     else
     {
         writer.WriteAttributeString(System.IdentityModel.XD.XmlSignatureDictionary.Algorithm, (XmlDictionaryString)null, this.algorithm);
     }
     if (this.algorithm == System.IdentityModel.XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value)
     {
         writer.WriteStartElement("", System.IdentityModel.XD.XmlSignatureDictionary.DigestMethod, System.IdentityModel.XD.XmlSignatureDictionary.Namespace);
         writer.WriteStartAttribute(System.IdentityModel.XD.XmlSignatureDictionary.Algorithm, (XmlDictionaryString)null);
         writer.WriteString(System.IdentityModel.XD.SecurityAlgorithmDictionary.Sha1Digest);
         writer.WriteEndAttribute();
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Beispiel #28
0
 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
 }
Beispiel #29
0
 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 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();
 }