Beispiel #1
0
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteStartElement("UsernameToken", Namespace);
     writer.WriteElementString("Username", Namespace, _credentials.UserName.UserName);
     writer.WriteElementString("Password", Namespace, _credentials.UserName.Password);
     writer.WriteEndElement();
 }
        private void WriteTo12Driver(XmlDictionaryWriter writer, EnvelopeVersion version)
        {
            writer.WriteStartElement(XD.MessageDictionary.Fault, version.DictionaryNamespace);
            writer.WriteStartElement(XD.Message12Dictionary.FaultCode, version.DictionaryNamespace);
            this.WriteFaultCode12Driver(writer, this.Code, version);
            writer.WriteEndElement();
            writer.WriteStartElement(XD.Message12Dictionary.FaultReason, version.DictionaryNamespace);
            FaultReason reason = this.Reason;

            for (int i = 0; i < reason.Translations.Count; i++)
            {
                FaultReasonText text = reason.Translations[i];
                writer.WriteStartElement(XD.Message12Dictionary.FaultText, version.DictionaryNamespace);
                writer.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", text.XmlLang);
                writer.WriteString(text.Text);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            if (this.Node.Length > 0)
            {
                writer.WriteElementString(XD.Message12Dictionary.FaultNode, version.DictionaryNamespace, this.Node);
            }
            if (this.Actor.Length > 0)
            {
                writer.WriteElementString(XD.Message12Dictionary.FaultRole, version.DictionaryNamespace, this.Actor);
            }
            if (this.HasDetail)
            {
                this.OnWriteDetail(writer, version);
            }
            writer.WriteEndElement();
        }
Beispiel #3
0
 //code omitted…
 protected override void OnWriteBodyContents(XmlDictionaryWriter w)
 {
     w.WriteStartElement("airfareRequest");
     w.WriteElementString("from", fromCity);
     w.WriteElementString("to", toCity);
     w.WriteEndElement();
 }
        public static void WriteLinkItem(LinkItem linkItem, XmlDictionaryWriter xmlWriter)
        {
            /* What the contents of the link item look like...
             *
             *  <b:Id>xs:int</b:Id>
             *  <b:Title>xs:string</b:Title>
             *  <b:Description>xs:string</b:Description>
             *  <b:DateStart>xs:dateTime</b:DateStart>
             *  <b:DateEnd>xs:dateTime</b:DateEnd>
             *  <b:Url>xs:string</b:Url>
             */
            xmlWriter.WriteStartElement("Id", ns);
            xmlWriter.WriteValue(linkItem.Id);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteElementString("Title", ns, linkItem.Title);
            xmlWriter.WriteElementString("Description", ns, linkItem.Description);

            xmlWriter.WriteStartElement("DateStart", ns);
            xmlWriter.WriteValue(linkItem.DateStart);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("DateEnd", ns);
            xmlWriter.WriteValue(linkItem.DateEnd);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteElementString("Url", ns, linkItem.Url);
        }
Beispiel #5
0
 protected override void OnWriteAddressHeaderContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("UsernameToken", Namespace);
     writer.WriteElementString("Username", Namespace, _username);
     writer.WriteElementString("Password", Namespace, _password);
     writer.WriteEndElement();
 }
Beispiel #6
0
        /// <summary>
        /// Called when the header content is serialized using the specified XML writer.
        /// </summary>
        /// <param name="writer">An <see cref="T:System.Xml.XmlDictionaryWriter" />.</param>
        /// <param name="messageVersion">Contains information related to the version of SOAP associated with a message and its exchange.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            //TimeStamp Header
            writer.WriteStartElement(WSUtilityPrefix, TimeStamp, WSUtilityNamespace);
            writer.WriteAttributeString(WSUtilityPrefix, IdAttributeName, WSUtilityNamespace, "Timestamp-" + this.GUID.ToString());
            writer.WriteElementString(CreatedElementName, WSUtilityNamespace, Created);
            writer.WriteElementString(ExpiresElementName, WSUtilityNamespace, Expires);
            writer.WriteEndElement();

            //UserNameToken Header
            writer.WriteStartElement(UsernameTokenPrefix, UsernameTokenName, UsernameTokenNamespace);
            writer.WriteAttributeString(WSUtilityPrefix, IdAttributeName, WSUtilityNamespace, "SecurityToken-" + this.GUID.ToString());
            writer.WriteElementString(UsernameElementName, UsernameTokenNamespace, this.UserName);
            writer.WriteStartElement(UsernameTokenPrefix, PasswordElementName, UsernameTokenNamespace);
            writer.WriteAttributeString(TypeAttributeName, PasswordDigestType);
            writer.WriteValue(PasswordDigest);
            writer.WriteEndElement();
            writer.WriteElementString(NonceElementName, UsernameTokenNamespace, Nonce);
            writer.WriteElementString(CreatedElementName, WSUtilityNamespace, Created);
            writer.WriteEndElement();
        }
        private static void WriteTraceData(TraceEventType eventType, int id, string traceIdentifier, string description, string methodName, Exception exception)
        {
            if (source.Switch.ShouldTrace(eventType))
            {
                MemoryStream        strm   = new MemoryStream();
                XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(strm);
                writer.WriteStartElement(TraceRecordName);
                writer.WriteAttributeString("xmlns", TraceRecordNs);
                writer.WriteElementString("TraceIdentifier", traceIdentifier);
                writer.WriteElementString("Description", description);
                writer.WriteElementString("AppDomain", AppDomain.CurrentDomain.FriendlyName);
                writer.WriteElementString("MethodName", methodName);
                writer.WriteElementString("Source", TraceHelper.TraceSourceName);
                if (exception != null)
                {
                    WriteException(writer, exception);
                }
                writer.WriteEndElement();
                writer.Flush();
                strm.Position = 0;
                XPathDocument doc = new XPathDocument(strm);

                source.TraceData(eventType, id, doc.CreateNavigator());
                writer.Close();
                strm.Close();
            }
        }
Beispiel #8
0
        private void WriteTo12Driver(XmlDictionaryWriter writer, EnvelopeVersion version)
        {
            writer.WriteStartElement(XD.MessageDictionary.Fault, version.DictionaryNamespace);
            writer.WriteStartElement(XD.Message12Dictionary.FaultCode, version.DictionaryNamespace);
            WriteFaultCode12Driver(writer, Code, version);
            writer.WriteEndElement();
            writer.WriteStartElement(XD.Message12Dictionary.FaultReason, version.DictionaryNamespace);
            FaultReason reason = Reason;

            for (int i = 0; i < reason.Translations.Count; i++)
            {
                FaultReasonText text = reason.Translations[i];
                writer.WriteStartElement(XD.Message12Dictionary.FaultText, version.DictionaryNamespace);
                writer.WriteAttributeString("xml", "lang", XmlUtil.XmlNs, text.XmlLang);
                writer.WriteString(text.Text);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            if (Node.Length > 0)
            {
                writer.WriteElementString(XD.Message12Dictionary.FaultNode, version.DictionaryNamespace, Node);
            }

            if (Actor.Length > 0)
            {
                writer.WriteElementString(XD.Message12Dictionary.FaultRole, version.DictionaryNamespace, Actor);
            }

            if (HasDetail)
            {
                OnWriteDetail(writer, version);
            }
            writer.WriteEndElement();
        }
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteAttributeString("xmlns", "wsse", null, NAMESPACE_SECURITY);
     writer.WriteStartElement("wsse:UsernameToken");
     writer.WriteElementString("wsse:Username", "YOUR_USERNAME");
     writer.WriteElementString("wsse:Password", "YOUR_PASSWORD");
     writer.WriteEndElement();
 }
Beispiel #10
0
 /// <summary>
 /// Called when the start header is serialized using the specified XML writer.
 /// </summary>
 /// <param name="writer">
 /// An <see cref="XmlDictionaryWriter"/> that is used to serialize the start header.
 /// </param>
 /// <param name="messageVersion">Unused.</param>
 /// <remarks>
 /// We override the default implementation in order to force a specific message
 /// layout, rather than relying on the default implementation which doesn't
 /// serialize in the expected manner.
 /// </remarks>
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteElementString("ActivityId", ActivityId.ToString());
     writer.WriteElementString("AccessToken", AccessToken);
     writer.WriteElementString("ExecutionId", ExecutionId.ToString());
     writer.WriteElementString("Action", Action);
     writer.WriteElementString("MomentStart", MomentStart.ToString("o", CultureInfo.InvariantCulture));
 }
 protected override void OnWriteFilterElementContents(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("LdapQuery", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/LdapQuery");
     writer.WriteElementString("Filter", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/LdapQuery", this.Filter);
     writer.WriteElementString("BaseObject", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/LdapQuery", this.SearchBase);
     writer.WriteElementString("Scope", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/LdapQuery", this.SearchScope);
     writer.WriteEndElement();
 }
 public void WriteArray()
 {
     w.WriteStartElement("root");              // name is ignored
     w.WriteAttributeString("type", "array");
     w.WriteElementString("item", "v1");
     w.WriteElementString("item", "v2");
     w.Close();
     Assert.AreEqual(@"[""v1"",""v2""]", ResultString, "#1");
 }
Beispiel #13
0
            public override void WriteContent(XmlDictionaryWriter writer, SecurityKeyIdentifierClause clause)
            {
                X509IssuerSerialKeyIdentifierClause issuerClause = clause as X509IssuerSerialKeyIdentifierClause;

                writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
                writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509IssuerSerial, XD.XmlSignatureDictionary.Namespace);
                writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509IssuerName, XD.XmlSignatureDictionary.Namespace, issuerClause.IssuerName);
                writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509SerialNumber, XD.XmlSignatureDictionary.Namespace, issuerClause.IssuerSerialNumber);
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
Beispiel #14
0
        protected void WritePasswordDigest(XmlDictionaryWriter writer)
        {
            string nonce     = GetNonce();
            string timestamp = GetTimestamp();
            string passHash  = GetPasswordHash(nonce, timestamp);

            writer.WriteStartElement("wsse:Password");
            writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
            writer.WriteValue(passHash);
            writer.WriteEndElement(); //wsse:Password
            writer.WriteElementString("wsse:Nonce", nonce);
            writer.WriteElementString("wsu:Created", timestamp);
        }
Beispiel #15
0
        protected void WriteBodyContentsCore(XmlDictionaryWriter w)
        {
            string ns = Constants.WstNamespace;

            w.WriteAttributeString("Context", Context);
            w.WriteElementString("t", "TokenType", ns, Constants.WsscContextToken);
            w.WriteElementString("t", "RequestType", ns, Constants.WstIssueRequest);
            w.WriteElementString("t", "KeySize", ns, XmlConvert.ToString(KeySize));
            if (BinaryExchange != null)
            {
                BinaryExchange.WriteTo(w);
            }
        }
Beispiel #16
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();
        }
        internal override void WriteContentsTo(XmlDictionaryWriter writer)
        {
            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");

            writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.KeyInfo, XD.XmlSignatureDictionary.Namespace);
            writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.RsaKeyValue, XD.XmlSignatureDictionary.Namespace);
            RSA rsa = (RSA)this.IdentityClaim.Resource;
            RSAParameters parameters = rsa.ExportParameters(false);
            writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.Modulus, XD.XmlSignatureDictionary.Namespace, Convert.ToBase64String(parameters.Modulus));
            writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.Exponent, XD.XmlSignatureDictionary.Namespace, Convert.ToBase64String(parameters.Exponent));
            writer.WriteEndElement();
            writer.WriteEndElement();
        }
Beispiel #18
0
        public static void SerializeClaimSet(ClaimSet claimSet, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer, XmlObjectSerializer claimSerializer)
        {
            if (claimSet is X509CertificateClaimSet)
            {
                X509CertificateClaimSet x509ClaimSet = (X509CertificateClaimSet)claimSet;
                writer.WriteStartElement(dictionary.X509CertificateClaimSet, dictionary.EmptyString);
                byte[] rawData = x509ClaimSet.X509Certificate.RawData;
                writer.WriteBase64(rawData, 0, rawData.Length);
                writer.WriteEndElement();
            }
            else if (claimSet == ClaimSet.System)
            {
                writer.WriteElementString(dictionary.SystemClaimSet, dictionary.EmptyString, String.Empty);
            }
            else if (claimSet == ClaimSet.Windows)
            {
                writer.WriteElementString(dictionary.WindowsClaimSet, dictionary.EmptyString, String.Empty);
            }
            else if (claimSet == ClaimSet.Anonymous)
            {
                writer.WriteElementString(dictionary.AnonymousClaimSet, dictionary.EmptyString, String.Empty);
            }
            else if (claimSet is WindowsClaimSet || claimSet is DefaultClaimSet)
            {
                writer.WriteStartElement(dictionary.ClaimSet, dictionary.EmptyString);
                writer.WriteStartElement(dictionary.PrimaryIssuer, dictionary.EmptyString);
                if (claimSet.Issuer == claimSet)
                {
                    writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
                }
                else
                {
                    SerializeClaimSet(claimSet.Issuer, dictionary, writer, serializer, claimSerializer);
                }
                writer.WriteEndElement();

                foreach (Claim claim in claimSet)
                {
                    writer.WriteStartElement(dictionary.Claim, dictionary.EmptyString);
                    SerializeClaim(claim, dictionary, writer, claimSerializer);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
            }
            else
            {
                serializer.WriteObject(writer, claimSet);
            }
        }
Beispiel #19
0
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.SetType(typeof(SessionSecurityToken));
            MemoryStream stream = new MemoryStream();

            using (XmlDictionaryWriter xmlDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null))
            {
                xmlDictionaryWriter.WriteStartElement("SecurityContextToken", "");

                xmlDictionaryWriter.WriteStartElement("Version", "");
                xmlDictionaryWriter.WriteValue("1");
                xmlDictionaryWriter.WriteEndElement();

                xmlDictionaryWriter.WriteElementString("SecureConversationVersion", "", (new Uri("http://schemas.xmlsoap.org/ws/2005/02/sc")).AbsoluteUri);

                xmlDictionaryWriter.WriteElementString("Id", "", "1");

                WriteElementStringAsUniqueId(xmlDictionaryWriter, "ContextId", "", "1");

                xmlDictionaryWriter.WriteStartElement("Key", "");
                xmlDictionaryWriter.WriteBase64(new byte[] { 0x01 }, 0, 1);
                xmlDictionaryWriter.WriteEndElement();

                WriteElementContentAsInt64(xmlDictionaryWriter, "EffectiveTime", "", 1);
                WriteElementContentAsInt64(xmlDictionaryWriter, "ExpiryTime", "", 1);
                WriteElementContentAsInt64(xmlDictionaryWriter, "KeyEffectiveTime", "", 1);
                WriteElementContentAsInt64(xmlDictionaryWriter, "KeyExpiryTime", "", 1);

                xmlDictionaryWriter.WriteStartElement("ClaimsPrincipal", "");
                xmlDictionaryWriter.WriteStartElement("Identities", "");
                xmlDictionaryWriter.WriteStartElement("Identity", "");
                xmlDictionaryWriter.WriteStartElement("BootStrapToken", "");
                xmlDictionaryWriter.WriteValue(B64Payload); // This is where the payload is
                xmlDictionaryWriter.WriteEndElement();
                xmlDictionaryWriter.WriteEndElement();
                xmlDictionaryWriter.WriteEndElement();
                xmlDictionaryWriter.WriteEndElement();

                xmlDictionaryWriter.WriteEndElement();
                xmlDictionaryWriter.Flush();

                stream.Position = 0;

                //Console.WriteLine(Encoding.ASCII.GetString(stream.ToArray()));

                info.AddValue("SessionToken", stream.ToArray());
            }
        }
Beispiel #20
0
 protected override void WriteRequestedTokenClosed(RequestSecurityTokenResponse rstr, XmlDictionaryWriter writer)
 {
     if (rstr.IsRequestedTokenClosed)
     {
         writer.WriteElementString(this.DriverDictionary.RequestedTokenClosed, this.DriverDictionary.Namespace, String.Empty);
     }
 }
        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            Contract.Requires(_provider != null);

            var searchPrefs = _provider.GetSearchPreferences();

            if (searchPrefs == null)
            {
                return;
            }

            void write <T>(string elementName, T value)
            {
                writer.WriteElementString(elementName, SuiteTalkSchemas.Messages, value.ToString());
            }

            if (searchPrefs.bodyFieldsOnly)
            {
                write(nameof(searchPrefs.bodyFieldsOnly), searchPrefs.bodyFieldsOnly);
            }
            if (searchPrefs.pageSizeSpecified)
            {
                write(nameof(searchPrefs.pageSize), searchPrefs.pageSize);
            }

            write(nameof(searchPrefs.returnSearchColumns), searchPrefs.returnSearchColumns);
        }
Beispiel #22
0
 private static void SerializeUsernamePasswordToken(XmlDictionaryWriter dictionaryWriter,
                                                    UserNameSecurityToken token)
 {
     dictionaryWriter.WriteStartElement(XD_SecurityJan2004Dictionary_Prefix_Value,
                                        XD_SecurityJan2004Dictionary_UserNameTokenElement,
                                        XD_SecurityJan2004Dictionary_Namespace);      // <wsse:UsernameToken
     dictionaryWriter.WriteAttributeString(XD_UtilityDictionary_Prefix_Value, XD_UtilityDictionary_IdAttribute,
                                           XD_UtilityDictionary_Namespace, token.Id); // wsu:Id="..."
     dictionaryWriter.WriteElementString(XD_SecurityJan2004Dictionary_Prefix_Value,
                                         XD_SecurityJan2004Dictionary_UserNameElement,
                                         XD_SecurityJan2004Dictionary_Namespace, token.UserName); // ><wsse:Username>...</wsse:Username>
     if (token.Password != null)
     {
         dictionaryWriter.WriteStartElement(XD_SecurityJan2004Dictionary_Prefix_Value,
                                            XD_SecurityJan2004Dictionary_PasswordElement,
                                            XD_SecurityJan2004Dictionary_Namespace);
         // tokenSerializer EmitBspRequiredAttributes is set to true
         dictionaryWriter.WriteAttributeString(XD_SecurityJan2004Dictionary_TypeAttribute, null,
                                               SecurityJan2004Strings_UPTokenPasswordTextValue);
         // emitBspRequiredAtribute
         dictionaryWriter.WriteString(token.Password); // <wsse:Password>...</wsse:Password>
         dictionaryWriter.WriteEndElement();
     }
     dictionaryWriter.WriteEndElement(); // </wsse:UsernameToken>
 }
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     if (_data != null && _data.Length > 0)
     {
         writer.WriteElementString("BODY", _data);
     }
 }
Beispiel #24
0
    public static void CreateTextReaderWriterTest()
    {
        string expected = "<localName>the value</localName>";

        using (MemoryStream stream = new MemoryStream())
        {
            using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8, false))
            {
                writer.WriteElementString("localName", "the value");
                writer.Flush();
                byte[]       bytes  = stream.ToArray();
                StreamReader reader = new StreamReader(stream);
                stream.Position = 0;
                string content = reader.ReadToEnd();
                Assert.Equal(expected, content);
                reader.Close();

                using (XmlDictionaryReader xreader = XmlDictionaryReader.CreateTextReader(bytes, new XmlDictionaryReaderQuotas()))
                {
                    xreader.Read();
                    string xml = xreader.ReadOuterXml();
                    Assert.Equal(expected, xml);
                }
            }
        }
    }
        public static void ReadElementContentAsStringDataExceedsMaxBytesPerReadQuota()
        {
            XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();

            quotas.MaxBytesPerRead = 4096;
            int contentLength = 8176;

            string              testString = new string('a', contentLength);
            string              returnedString;
            XmlDictionary       dict      = new XmlDictionary();
            XmlDictionaryString dictEntry = dict.Add("Value");

            using (var ms = new MemoryStream())
            {
                XmlDictionaryWriter xmlWriter = XmlDictionaryWriter.CreateBinaryWriter(ms, dict);
                xmlWriter.WriteElementString(dictEntry, XmlDictionaryString.Empty, testString);
                xmlWriter.Flush();
                ms.Position = 0;
                XmlDictionaryReader xmlReader = XmlDictionaryReader.CreateBinaryReader(ms, dict, quotas);
                xmlReader.Read();
                returnedString = xmlReader.ReadElementContentAsString();
            }

            Assert.Equal(testString, returnedString);
        }
        public static void GetNonAtomizedNamesTest()
        {
            string localNameTest    = "localNameTest";
            string namespaceUriTest = "http://www.msn.com/";
            var    encoding         = Encoding.UTF8;
            var    rndGen           = new Random();
            int    byteArrayLength  = rndGen.Next(100, 2000);

            byte[] byteArray = new byte[byteArrayLength];
            rndGen.NextBytes(byteArray);
            MemoryStream        ms     = new MemoryStream();
            XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(ms, encoding);

            writer.WriteElementString(localNameTest, namespaceUriTest, "value");
            writer.Flush();
            ms.Position = 0;
            XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(ms, encoding, XmlDictionaryReaderQuotas.Max, null);
            bool success = reader.ReadToDescendant(localNameTest);

            Assert.True(success);
            string localName;
            string namespaceUriStr;

            reader.GetNonAtomizedNames(out localName, out namespaceUriStr);
            Assert.Equal(localNameTest, localName);
            Assert.Equal(namespaceUriTest, namespaceUriStr);
            writer.Close();
        }
Beispiel #27
0
        public virtual void WriteXml(XmlDictionaryWriter writer,
                                     SamlSerializer samlSerializer,
                                     SecurityTokenSerializer keyInfoSerializer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (samlSerializer == null)
            {
                throw new ArgumentNullException("samlSerializer");
            }
            if (references.Count == 0 && assertions.Count == 0)
            {
                throw new SecurityTokenException("At least either one of AssertionIDReference or Assertion must exist in SAML Evidence.");
            }

            writer.WriteStartElement("saml", "Evidence", SamlConstants.Namespace);
            foreach (string s in references)
            {
                writer.WriteElementString("saml", "AssertionIDReference", SamlConstants.Namespace, s);
            }
            foreach (SamlAssertion a in assertions)
            {
                a.WriteXml(writer, samlSerializer, keyInfoSerializer);
            }
            writer.WriteEndElement();
        }
            public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause)
            {
                EncryptedKeyIdentifierClause clause = keyIdentifierClause as EncryptedKeyIdentifierClause;

                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptedKey, this.NamespaceUri);
                if (clause.EncryptionMethod != null)
                {
                    writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptionMethod, this.NamespaceUri);
                    writer.WriteAttributeString(XD.XmlEncryptionDictionary.AlgorithmAttribute, null, clause.EncryptionMethod);
                    if (clause.EncryptionMethod == XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value)
                    {
                        writer.WriteStartElement("", XD.XmlSignatureDictionary.DigestMethod, XD.XmlSignatureDictionary.Namespace);
                        writer.WriteAttributeString(XD.XmlSignatureDictionary.Algorithm, null, "http://www.w3.org/2000/09/xmldsig#sha1");
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
                if (clause.EncryptingKeyIdentifier != null)
                {
                    this.tokenSerializer.WriteKeyIdentifier(writer, clause.EncryptingKeyIdentifier);
                }
                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherData, this.NamespaceUri);
                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherValue, this.NamespaceUri);
                byte[] encryptedKey = clause.GetEncryptedKey();
                writer.WriteBase64(encryptedKey, 0, encryptedKey.Length);
                writer.WriteEndElement();
                writer.WriteEndElement();
                if (clause.CarriedKeyName != null)
                {
                    writer.WriteElementString(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CarriedKeyName, this.NamespaceUri, clause.CarriedKeyName);
                }
                writer.WriteEndElement();
            }
Beispiel #29
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            string title = string.Format(CultureInfo.InvariantCulture, "{0} Service", this.serviceName);

            writer.WriteStartElement("HTML");
            writer.WriteStartElement("HEAD");
            writer.WriteElementString("TITLE", title);
            writer.WriteEndElement(); // HEAD

            writer.WriteStartElement("BODY");
            writer.WriteStartElement("H1");
            writer.WriteString(title);
            writer.WriteEndElement(); // H1

            writer.WriteStartElement("B");
            writer.WriteString(string.Format(CultureInfo.InvariantCulture, "The service '{0}' at address:", this.serviceName));
            writer.WriteStartElement("UL");
            writer.WriteStartElement("A");
            writer.WriteAttributeString("href", this.serviceUrl);
            writer.WriteString(this.serviceUrl);
            writer.WriteEndElement(); // A
            writer.WriteEndElement(); // UL
            writer.WriteString(" has been compiled successfully.");
            writer.WriteEndElement(); // B
            writer.WriteEndElement(); // HTML
            writer.WriteEndElement(); // BODY
        }
Beispiel #30
0
            protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
            {
                writer.WriteStartElement("Fault", _constants.EnvelopeNamespace);

                WriteFaultCodeElement(writer, Fault.Code, "Code");
                //writer.WriteElementString("Value", Constants.Soap12EnvelopeNamespace, GetFaultCodeString(Fault.Code));

                var reason = Fault.Reason.GetMatchingTranslation();

                writer.WriteStartElement("Reason", _constants.EnvelopeNamespace);
                writer.WriteStartElement("Text", _constants.EnvelopeNamespace);
                writer.WriteAttributeString("xml", "lang", _constants.XmlNamespace, reason.XmlLang);
                writer.WriteString(reason.Text);
                writer.WriteEndElement();
                writer.WriteEndElement();

                writer.WriteElementString("Node", _constants.EnvelopeNamespace, Fault.Node);

                if (Fault.HasDetail)
                {
                    using (var reader = Fault.GetReaderAtDetailContents())
                    {
                        writer.WriteStartElement("Detail", _constants.EnvelopeNamespace);
                        writer.WriteElement(reader);
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
            }