GetAttribute() public method

public GetAttribute ( System localName, System namespaceUri ) : string
localName System
namespaceUri System
return string
 public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize)
 {
     this.ValidateReadState();
     reader.MoveToStartElement(this.OpeningElementName, NamespaceUri);
     this.encoding = reader.GetAttribute(EncodingAttribute, null);
     this.id = reader.GetAttribute(System.ServiceModel.XD.XmlEncryptionDictionary.Id, null) ?? System.ServiceModel.Security.SecurityUniqueId.Create().Value;
     this.wsuId = reader.GetAttribute(System.ServiceModel.XD.XmlEncryptionDictionary.Id, System.ServiceModel.XD.UtilityDictionary.Namespace) ?? System.ServiceModel.Security.SecurityUniqueId.Create().Value;
     this.mimeType = reader.GetAttribute(MimeTypeAttribute, null);
     this.type = reader.GetAttribute(TypeAttribute, null);
     this.ReadAdditionalAttributes(reader);
     reader.Read();
     if (reader.IsStartElement(EncryptionMethodElement.ElementName, NamespaceUri))
     {
         this.encryptionMethod.ReadFrom(reader);
     }
     if (this.tokenSerializer.CanReadKeyIdentifier(reader))
     {
         this.KeyIdentifier = this.tokenSerializer.ReadKeyIdentifier(reader);
     }
     reader.ReadStartElement(CipherDataElementName, NamespaceUri);
     reader.ReadStartElement(CipherValueElementName, NamespaceUri);
     if (maxBufferSize == 0L)
     {
         this.ReadCipherData(reader);
     }
     else
     {
         this.ReadCipherData(reader, maxBufferSize);
     }
     reader.ReadEndElement();
     reader.ReadEndElement();
     this.ReadAdditionalElements(reader);
     reader.ReadEndElement();
     this.State = EncryptionState.Read;
 }
Exemplo n.º 2
0
        public virtual void WriteNode(XmlDictionaryReader reader, bool defattr)
        {
            ArgumentNullException.ThrowIfNull(reader);

            int d = (reader.NodeType == XmlNodeType.None ? -1 : reader.Depth);

            do
            {
                XmlNodeType nodeType = reader.NodeType;
                Type?       type;
                if (nodeType == XmlNodeType.Text || nodeType == XmlNodeType.Whitespace || nodeType == XmlNodeType.SignificantWhitespace)
                {
                    // This will advance if necessary, so we don't need to call Read() explicitly
                    WriteTextNode(reader, false);
                }
                else if (reader.Depth > d && reader.IsStartArray(out type))
                {
                    WriteArrayNode(reader, type);
                }
                else
                {
                    // These will not advance, so we must call Read() explicitly
                    switch (nodeType)
                    {
                    case XmlNodeType.Element:
                        WriteElementNode(reader, defattr);
                        break;

                    case XmlNodeType.CDATA:
                        WriteCData(reader.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        WriteEntityRef(reader.Name);
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        WriteProcessingInstruction(reader.Name, reader.Value);
                        break;

                    case XmlNodeType.DocumentType:
                        WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                        break;

                    case XmlNodeType.Comment:
                        WriteComment(reader.Value);
                        break;

                    case XmlNodeType.EndElement:
                        WriteFullEndElement();
                        break;
                    }
                    if (!reader.Read())
                    {
                        break;
                    }
                }
            }while (d < reader.Depth || (d == reader.Depth && reader.NodeType == XmlNodeType.EndElement));
        }
Exemplo n.º 3
0
        private Expression<Func<ClaimsPrincipal, bool>> ReadClaim(XmlDictionaryReader rdr)
        {
            string claimType = rdr.GetAttribute("claimType");
            string claimValue = rdr.GetAttribute("claimValue");

            Expression<Func<ClaimsPrincipal, bool>> hasClaim = icp => HasClaim(icp, claimType, claimValue);

            rdr.Read();

            return hasClaim;
        }
Exemplo n.º 4
0
		public static void Deserialize(XmlDictionaryReader reader, out IList<DirectoryControl> controls, bool mustBePresent, bool fullChecks)
		{
			string str = null;
			string str1 = null;
			bool flag;
			byte[] numArray = null;
			controls = new List<DirectoryControl>();
			if (mustBePresent || reader.IsStartElement("controls", "http://schemas.microsoft.com/2008/1/ActiveDirectory"))
			{
				reader.ReadFullStartElement("controls", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
				while (reader.IsStartElement("control", "http://schemas.microsoft.com/2008/1/ActiveDirectory"))
				{
					string attribute = reader.GetAttribute("type");
					string attribute1 = reader.GetAttribute("criticality");
					reader.Read();
					if (!reader.IsStartElement("controlValue", "http://schemas.microsoft.com/2008/1/ActiveDirectory"))
					{
						numArray = null;
					}
					else
					{
						string attribute2 = reader.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
						if (attribute2 != null)
						{
							XmlUtility.SplitPrefix(attribute2, out str, out str1);
							numArray = reader.ReadElementContentAsBase64();
						}
						else
						{
							throw new ArgumentException();
						}
					}
					if (!string.Equals("true", attribute1))
					{
						flag = false;
					}
					else
					{
						flag = true;
					}
					DirectoryControl directoryControl = new DirectoryControl(attribute, numArray, flag, true);
					controls.Add(directoryControl);
					reader.Read();
				}
				return;
			}
			else
			{
				return;
			}
		}
        public void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.EncryptionMethod, XmlEncryptionConstants.Namespace ) )
            {
                return;
            }

            _algorithm = reader.GetAttribute( XmlEncryptionConstants.Attributes.Algorithm, null );

            if ( !reader.IsEmptyElement )
            {
                //
                // Trace unread missing element
                //

                string xml = reader.ReadOuterXml();
                if ( DiagnosticUtility.ShouldTraceWarning )
                {
                    TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) );
                }
            }
            else
            {
                //
                // Read to the next element
                //
                reader.Read();
            }
        }
Exemplo n.º 6
0
		void AssertNode (int depth, string localName, XmlNodeType nodeType, string value, string type, XmlDictionaryReader reader, string label)
		{
			Assert.AreEqual (localName, reader.LocalName, label + ".LocalName");
			Assert.AreEqual (nodeType, reader.NodeType, label + ".NodeType");
			Assert.AreEqual (value, reader.Value, label + ".Value");
			Assert.AreEqual (type, reader.GetAttribute ("type"), label + ".GetAttribute('type')");
		}
 public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
 {
     string str2;
     string str3;
     if (reader == null)
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
     }
     if (samlSerializer == null)
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     string attribute = reader.GetAttribute(samlDictionary.AuthorityKind, null);
     if (string.IsNullOrEmpty(attribute))
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthorityBindingMissingAuthorityKindOnRead")));
     }
     string[] strArray = attribute.Split(new char[] { ':' });
     if (strArray.Length > 2)
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthorityBindingInvalidAuthorityKind")));
     }
     if (strArray.Length == 2)
     {
         str3 = strArray[0];
         str2 = strArray[1];
     }
     else
     {
         str3 = string.Empty;
         str2 = strArray[0];
     }
     string ns = reader.LookupNamespace(str3);
     this.authorityKind = new XmlQualifiedName(str2, ns);
     this.binding = reader.GetAttribute(samlDictionary.Binding, null);
     if (string.IsNullOrEmpty(this.binding))
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthorityBindingMissingBindingOnRead")));
     }
     this.location = reader.GetAttribute(samlDictionary.Location, null);
     if (string.IsNullOrEmpty(this.location))
     {
         throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthorityBindingMissingLocationOnRead")));
     }
     if (reader.IsEmptyElement)
     {
         reader.MoveToContent();
         reader.Read();
     }
     else
     {
         reader.MoveToContent();
         reader.Read();
         reader.ReadEndElement();
     }
 }
 public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
 {
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     string attribute = reader.GetAttribute(samlDictionary.NotBefore, null);
     if (!string.IsNullOrEmpty(attribute))
     {
         this.notBefore = DateTime.ParseExact(attribute, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();
     }
     attribute = reader.GetAttribute(samlDictionary.NotOnOrAfter, null);
     if (!string.IsNullOrEmpty(attribute))
     {
         this.notOnOrAfter = DateTime.ParseExact(attribute, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();
     }
     if (reader.IsEmptyElement)
     {
         reader.MoveToContent();
         reader.Read();
     }
     else
     {
         reader.MoveToContent();
         reader.Read();
         while (reader.IsStartElement())
         {
             SamlCondition item = samlSerializer.LoadCondition(reader, keyInfoSerializer, outOfBandTokenResolver);
             if (item == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadCondtion")));
             }
             this.conditions.Add(item);
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Reads the body of an object
        /// </summary>
        public override object ReadObject(System.Xml.XmlDictionaryReader reader, bool verifyObjectName)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            reader.MoveToContent();
            bool isSelfClosed = reader.IsEmptyElement, isNil = reader.GetAttribute("nil") == "true";

            reader.ReadStartElement(PROTO_ELEMENT);

            // explicitly null
            if (isNil)
            {
                if (!isSelfClosed)
                {
                    reader.ReadEndElement();
                }
                return(null);
            }
            if (isSelfClosed) // no real content
            {
                if (isList || isEnum)
                {
                    return(model.Deserialize(Stream.Null, null, type, null));
                }
                using (ProtoReader protoReader = new ProtoReader(Stream.Null, model, null))
                {
                    return(model.Deserialize(key, null, protoReader));
                }
            }

            object result;

            Helpers.DebugAssert(reader.CanReadBinaryContent, "CanReadBinaryContent");
            using (MemoryStream ms = new MemoryStream(reader.ReadContentAsBase64()))
            {
                if (isList || isEnum)
                {
                    result = model.Deserialize(ms, null, type, null);
                }
                else
                {
                    using (ProtoReader protoReader = new ProtoReader(ms, model, null))
                    {
                        result = model.Deserialize(key, null, protoReader);
                    }
                }
            }
            reader.ReadEndElement();
            return(result);
        }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     this.Id = reader.GetAttribute(dictionaryManager.UtilityDictionary.IdAttribute, null);
     reader.Read();
     this.signedInfo.ReadFrom(reader, this.signedXml.TransformFactory, dictionaryManager);
     this.signatureValueElement.ReadFrom(reader, dictionaryManager);
     if (this.signedXml.SecurityTokenSerializer.CanReadKeyIdentifier(reader))
     {
         this.keyIdentifier = this.signedXml.SecurityTokenSerializer.ReadKeyIdentifier(reader);
     }
     reader.ReadEndElement();
 }
Exemplo n.º 11
0
        public virtual void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( reader.IsStartElement( XD.XmlSignatureDictionary.KeyInfo.Value, XD.XmlSignatureDictionary.Namespace.Value ) )
            {
                // <KeyInfo>
                reader.ReadStartElement();

                while ( reader.IsStartElement() )
                {
                    // <RetrievalMethod>
                    if ( reader.IsStartElement( XmlSignatureConstants.Elements.RetrievalMethod, XD.XmlSignatureDictionary.Namespace.Value ) )
                    {
                        string method = reader.GetAttribute( XD.XmlSignatureDictionary.URI.Value );
                        if ( !string.IsNullOrEmpty( method ) )
                        {
                            _retrieval = method;
                        }
                        reader.Skip();
                    }
                    // check if internal serializer can handle clause
                    else if ( _keyInfoSerializer.CanReadKeyIdentifierClause( reader ) )
                    {
                        _ski.Add( _keyInfoSerializer.ReadKeyIdentifierClause( reader ) );
                    }
                    // trace we skipped over an element
                    else if ( reader.IsStartElement() )
                    {
                        string xml = reader.ReadOuterXml();

                        if ( DiagnosticUtility.ShouldTraceWarning )
                        {
                            TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8023, reader.Name, reader.NamespaceURI, xml ) );
                        }
                    }
                    reader.MoveToContent();
                }

                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
Exemplo n.º 12
0
            public override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
            {
                string encryptionMethod = null;
                string carriedKeyName = null;
                SecurityKeyIdentifier encryptingKeyIdentifier = null;
                byte[] encryptedKey = null;

                reader.ReadStartElement(XD.XmlEncryptionDictionary.EncryptedKey, NamespaceUri);
                
                if (reader.IsStartElement(XD.XmlEncryptionDictionary.EncryptionMethod, NamespaceUri))
                {
                    encryptionMethod = reader.GetAttribute(XD.XmlEncryptionDictionary.AlgorithmAttribute, null);
                    bool isEmptyElement = reader.IsEmptyElement;
                    reader.ReadStartElement();
                    if (!isEmptyElement)
                    {
                        while (reader.IsStartElement())
                        {
                            reader.Skip();
                        }
                        reader.ReadEndElement();
                    }
                }

                if (this.securityTokenSerializer.CanReadKeyIdentifier(reader))
                {
                    encryptingKeyIdentifier = this.securityTokenSerializer.ReadKeyIdentifier(reader);
                }
                
                reader.ReadStartElement(XD.XmlEncryptionDictionary.CipherData, NamespaceUri);
                reader.ReadStartElement(XD.XmlEncryptionDictionary.CipherValue, NamespaceUri);
                encryptedKey = reader.ReadContentAsBase64();
                reader.ReadEndElement();
                reader.ReadEndElement();

                if (reader.IsStartElement(XD.XmlEncryptionDictionary.CarriedKeyName, NamespaceUri))
                {
                    reader.ReadStartElement();
                    carriedKeyName = reader.ReadString();                    
                    reader.ReadEndElement();
                }
                
                reader.ReadEndElement();

                return new EncryptedKeyIdentifierClause(encryptedKey, encryptionMethod, encryptingKeyIdentifier, carriedKeyName);
            }
 internal static string ReadEmptyElementAndRequiredAttribute(XmlDictionaryReader reader, XmlDictionaryString name, XmlDictionaryString namespaceUri, XmlDictionaryString attributeName, out string prefix)
 {
     reader.MoveToStartElement(name, namespaceUri);
     prefix = reader.Prefix;
     bool isEmptyElement = reader.IsEmptyElement;
     string attribute = reader.GetAttribute(attributeName, null);
     if (attribute == null)
     {
         OnRequiredAttributeMissing(attributeName.Value, null);
     }
     reader.Read();
     if (!isEmptyElement)
     {
         reader.ReadEndElement();
     }
     return attribute;
 }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     bool isEmptyElement = reader.IsEmptyElement;
     this.algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     if (this.algorithm == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("RequiredAttributeMissing", new object[] { dictionaryManager.XmlSignatureDictionary.Algorithm, this.elementName })));
     }
     reader.Read();
     reader.MoveToContent();
     if (!isEmptyElement)
     {
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
 public void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     reader.Read();
     while (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace))
     {
         string attribute = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
         Transform transform = transformFactory.CreateTransform(attribute);
         transform.ReadFrom(reader, dictionaryManager);
         this.Add(transform);
     }
     reader.MoveToContent();
     reader.ReadEndElement();
     if (this.TransformCount == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(System.IdentityModel.SR.GetString("AtLeastOneTransformRequired")));
     }
 }
Exemplo n.º 16
0
 public virtual void ReadXml(XmlDictionaryReader reader)
 {
     if (reader == null)
     {
         throw DiagnosticUtil.ExceptionUtil.ThrowHelperArgumentNull("reader");
     }
     reader.MoveToContent();
     if (reader.IsStartElement("KeyInfo", "http://www.w3.org/2000/09/xmldsig#"))
     {
         reader.ReadStartElement();
         while (reader.IsStartElement())
         {
             if (reader.IsStartElement("RetrievalMethod", "http://www.w3.org/2000/09/xmldsig#"))
             {
                 string attribute = reader.GetAttribute("URI");
                 if (!string.IsNullOrEmpty(attribute))
                 {
                     this._retrieval = attribute;
                 }
                 reader.Skip();
             }
             else if (this._keyInfoSerializer.CanReadKeyIdentifierClause(reader))
             {
                 this._ski.Add(this._keyInfoSerializer.ReadKeyIdentifierClause(reader));
             }
             else if (reader.IsStartElement())
             {
                 string str2 = reader.ReadOuterXml();
                 //if (DiagnosticUtil.TraceUtil.ShouldTrace(TraceEventType.Warning))
                 //{
                 //    DiagnosticUtil.TraceUtil.TraceString(TraceEventType.Warning, SR.GetString("ID8023", new object[] { reader.Name, reader.NamespaceURI, str2 }), new object[0]);
                 //}
             }
             reader.MoveToContent();
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
 public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
 {
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     if (reader.IsStartElement(samlDictionary.Action, samlDictionary.Namespace))
     {
         this.ns = reader.GetAttribute(samlDictionary.ActionNamespaceAttribute, null);
         reader.MoveToContent();
         this.action = reader.ReadString();
         if (string.IsNullOrEmpty(this.action))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLActionNameRequiredOnRead")));
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
 }
 public virtual void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
 {
     if (reader == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("samlSerializer");
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     reader.MoveToContent();
     reader.Read();
     if (reader.IsStartElement(samlDictionary.NameIdentifier, samlDictionary.Namespace))
     {
         this.nameFormat = reader.GetAttribute(samlDictionary.NameIdentifierFormat, null);
         this.nameQualifier = reader.GetAttribute(samlDictionary.NameIdentifierNameQualifier, null);
         reader.MoveToContent();
         this.name = reader.ReadString();
         if (this.name == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLNameIdentifierMissingIdentifierValueOnRead")));
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
     if (reader.IsStartElement(samlDictionary.SubjectConfirmation, samlDictionary.Namespace))
     {
         reader.MoveToContent();
         reader.Read();
         while (reader.IsStartElement(samlDictionary.SubjectConfirmationMethod, samlDictionary.Namespace))
         {
             string str = reader.ReadString();
             if (string.IsNullOrEmpty(str))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.SubjectConfirmationMethod.Value })));
             }
             this.confirmationMethods.Add(str);
             reader.MoveToContent();
             reader.ReadEndElement();
         }
         if (this.confirmationMethods.Count == 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLSubjectConfirmationClauseMissingConfirmationMethodOnRead")));
         }
         if (reader.IsStartElement(samlDictionary.SubjectConfirmationData, samlDictionary.Namespace))
         {
             reader.MoveToContent();
             this.confirmationData = reader.ReadString();
             reader.MoveToContent();
             reader.ReadEndElement();
         }
         if (reader.IsStartElement(samlSerializer.DictionaryManager.XmlSignatureDictionary.KeyInfo, samlSerializer.DictionaryManager.XmlSignatureDictionary.Namespace))
         {
             XmlDictionaryReader reader2 = XmlDictionaryReader.CreateDictionaryReader(reader);
             this.securityKeyIdentifier = SamlSerializer.ReadSecurityKeyIdentifier(reader2, keyInfoSerializer);
             this.crypto = SamlSerializer.ResolveSecurityKey(this.securityKeyIdentifier, outOfBandTokenResolver);
             if (this.crypto == null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SamlUnableToExtractSubjectKey")));
             }
             this.subjectToken = SamlSerializer.ResolveSecurityToken(this.securityKeyIdentifier, outOfBandTokenResolver);
         }
         if ((this.confirmationMethods.Count == 0) && string.IsNullOrEmpty(this.name))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLSubjectRequiresNameIdentifierOrConfirmationMethodOnRead")));
         }
         reader.MoveToContent();
         reader.ReadEndElement();
     }
     reader.MoveToContent();
     reader.ReadEndElement();
 }
        public virtual void WriteNode(XmlDictionaryReader reader, bool defattr)
        {
            XmlNodeType type;
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            int num = (reader.NodeType == XmlNodeType.None) ? -1 : reader.Depth;
        Label_002A:
            type = reader.NodeType;
            switch (type)
            {
                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    this.WriteTextNode(reader, false);
                    goto Label_0136;

                default:
                    Type type2;
                    if ((reader.Depth > num) && reader.IsStartArray(out type2))
                    {
                        this.WriteArrayNode(reader, type2);
                        goto Label_0136;
                    }
                    switch (type)
                    {
                        case XmlNodeType.Element:
                            this.WriteElementNode(reader, defattr);
                            goto Label_012D;

                        case XmlNodeType.CDATA:
                            this.WriteCData(reader.Value);
                            goto Label_012D;

                        case XmlNodeType.EntityReference:
                            this.WriteEntityRef(reader.Name);
                            goto Label_012D;

                        case XmlNodeType.ProcessingInstruction:
                        case XmlNodeType.XmlDeclaration:
                            this.WriteProcessingInstruction(reader.Name, reader.Value);
                            goto Label_012D;

                        case XmlNodeType.Comment:
                            this.WriteComment(reader.Value);
                            goto Label_012D;

                        case XmlNodeType.DocumentType:
                            this.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                            goto Label_012D;

                        case XmlNodeType.EndElement:
                            this.WriteFullEndElement();
                            goto Label_012D;
                    }
                    break;
            }
        Label_012D:
            if (!reader.Read())
            {
                return;
            }
        Label_0136:
            if ((num < reader.Depth) || ((num == reader.Depth) && (reader.NodeType == XmlNodeType.EndElement)))
            {
                goto Label_002A;
            }
        }
        public override void ReadXml( XmlDictionaryReader reader )
        {
            if ( reader == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( "reader" );
            }

            reader.MoveToContent();
            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.EncryptedKey, XmlEncryptionConstants.Namespace ) )
            {
                throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4187 ) );
            }

            _recipient = reader.GetAttribute( XmlEncryptionConstants.Attributes.Recipient, null );

            //<EncryptedKey> extends <EncryptedType>
            // base will read the start element and end elements
            base.ReadXml( reader );
        }
        public override void ReadExtensions( XmlDictionaryReader reader )
        {
            reader.MoveToContent();
            if ( reader.IsStartElement( XmlEncryptionConstants.Elements.ReferenceList, XmlEncryptionConstants.Namespace ) )
            {
                reader.ReadStartElement();

                // could have data or key references.  these are the only two possible elements sec 3.6 xml enc.
                // 3.6 The ReferenceList Element specifies there is a choice. Once one is chosen, it is fixed.
                if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace ) )
                {
                    while ( reader.IsStartElement() )
                    {
                        if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace ) )
                        {
                            string dataRef = reader.GetAttribute( XmlEncryptionConstants.Attributes.Uri );
                            if ( !string.IsNullOrEmpty( dataRef ) )
                            {
                                _dataReferences.Add( dataRef );
                            }
                            reader.Skip();
                        }
                        else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace ) )
                        {
                            throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4189 ) );
                        }
                        else
                        {
                            string xml = reader.ReadOuterXml();
                            if ( DiagnosticUtility.ShouldTraceWarning )
                            {
                                TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) );
                            }
                        }
                    }
                }
                else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace ) )
                {
                    while ( reader.IsStartElement() )
                    {
                        if ( reader.IsStartElement( XmlEncryptionConstants.Elements.KeyReference, XmlEncryptionConstants.Namespace ) )
                        {
                            string keyRef = reader.GetAttribute( XmlEncryptionConstants.Attributes.Uri );
                            if ( !string.IsNullOrEmpty( keyRef ) )
                            {
                                _keyReferences.Add( keyRef );
                            }
                            reader.Skip();
                        }
                        else if ( reader.IsStartElement( XmlEncryptionConstants.Elements.DataReference, XmlEncryptionConstants.Namespace ) )
                        {
                            throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4190 ) );
                        }
                        else
                        {
                            string xml = reader.ReadOuterXml();
                            if ( DiagnosticUtility.ShouldTraceWarning )
                            {
                                TraceUtility.TraceString( System.Diagnostics.TraceEventType.Warning, SR.GetString( SR.ID8024, reader.Name, reader.NamespaceURI, xml ) );
                            }
                        }
                    }
                }
                else
                {
                    // there must be at least one reference.
                    throw DiagnosticUtility.ThrowHelperXml( reader, SR.GetString( SR.ID4191 ) );
                }

                reader.MoveToContent();
                if ( reader.IsStartElement( XmlEncryptionConstants.Elements.CarriedKeyName, XmlEncryptionConstants.Namespace ) )
                {
                    reader.ReadStartElement();
                    _carriedName = reader.ReadString();
                    reader.ReadEndElement();
                }

                // </ReferenceList>
                reader.ReadEndElement();
            }
        }
 public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.SignatureValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     this.Id = reader.GetAttribute("Id", null);
     reader.Read();
     this.signatureText = reader.ReadString();
     this.signatureValue = Convert.FromBase64String(this.signatureText.Trim());
     reader.ReadEndElement();
 }
Exemplo n.º 23
0
 public override string GetAttribute(int index)
 {
     return(reader.GetAttribute(index));
 }
Exemplo n.º 24
0
        public virtual void WriteNode(XmlDictionaryReader reader, bool defattr)
        {
            XmlNodeType type;

            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            int num = (reader.NodeType == XmlNodeType.None) ? -1 : reader.Depth;

Label_002A:
            type = reader.NodeType;
            switch (type)
            {
            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                this.WriteTextNode(reader, false);
                goto Label_0136;

            default:
                Type type2;
                if ((reader.Depth > num) && reader.IsStartArray(out type2))
                {
                    this.WriteArrayNode(reader, type2);
                    goto Label_0136;
                }
                switch (type)
                {
                case XmlNodeType.Element:
                    this.WriteElementNode(reader, defattr);
                    goto Label_012D;

                case XmlNodeType.CDATA:
                    this.WriteCData(reader.Value);
                    goto Label_012D;

                case XmlNodeType.EntityReference:
                    this.WriteEntityRef(reader.Name);
                    goto Label_012D;

                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.XmlDeclaration:
                    this.WriteProcessingInstruction(reader.Name, reader.Value);
                    goto Label_012D;

                case XmlNodeType.Comment:
                    this.WriteComment(reader.Value);
                    goto Label_012D;

                case XmlNodeType.DocumentType:
                    this.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                    goto Label_012D;

                case XmlNodeType.EndElement:
                    this.WriteFullEndElement();
                    goto Label_012D;
                }
                break;
            }
Label_012D:
            if (!reader.Read())
            {
                return;
            }
Label_0136:
            if ((num < reader.Depth) || ((num == reader.Depth) && (reader.NodeType == XmlNodeType.EndElement)))
            {
                goto Label_002A;
            }
        }
 public virtual void WriteNode(XmlDictionaryReader reader, bool defattr)
 {
     if (reader == null)
         throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
     int d = (reader.NodeType == XmlNodeType.None ? -1 : reader.Depth);
     do
     {
         XmlNodeType nodeType = reader.NodeType;
         Type type;
         if (nodeType == XmlNodeType.Text || nodeType == XmlNodeType.Whitespace || nodeType == XmlNodeType.SignificantWhitespace)
         {
             // This will advance if necessary, so we don't need to call Read() explicitly
             WriteTextNode(reader, false);
         }
         else if (reader.Depth > d && reader.IsStartArray(out type))
         {
             WriteArrayNode(reader, type);
         }
         else
         {
             // These will not advance, so we must call Read() explicitly
             switch (nodeType)
             {
                 case XmlNodeType.Element:
                     WriteElementNode(reader, defattr);
                     break;
                 case XmlNodeType.CDATA:
                     WriteCData(reader.Value);
                     break;
                 case XmlNodeType.EntityReference:
                     WriteEntityRef(reader.Name);
                     break;
                 case XmlNodeType.XmlDeclaration:
                 case XmlNodeType.ProcessingInstruction:
                     WriteProcessingInstruction(reader.Name, reader.Value);
                     break;
                 case XmlNodeType.DocumentType:
                     WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                     break;
                 case XmlNodeType.Comment:
                     WriteComment(reader.Value);
                     break;
                 case XmlNodeType.EndElement:
                     WriteFullEndElement();
                     break;
             }
             if (!reader.Read())
                 break;
         }
     }
     while (d < reader.Depth || (d == reader.Depth && reader.NodeType == XmlNodeType.EndElement));
 }
 public void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager)
 {
     reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Reference, dictionaryManager.XmlSignatureDictionary.Namespace);
     this.prefix = reader.Prefix;
     this.Id = reader.GetAttribute("Id", null);
     this.Uri = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.URI, null);
     this.Type = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Type, null);
     reader.Read();
     if (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Transforms, dictionaryManager.XmlSignatureDictionary.Namespace))
     {
         this.transformChain.ReadFrom(reader, transformFactory, dictionaryManager);
     }
     this.digestMethodElement.ReadFrom(reader, dictionaryManager);
     this.digestValueElement.ReadFrom(reader, dictionaryManager);
     reader.MoveToContent();
     reader.ReadEndElement();
 }
        public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager, bool preserveComments)
        {
            XmlDictionaryString elementName = this.isCanonicalizationMethod ?
                dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod : dictionaryManager.XmlSignatureDictionary.Transform;
            reader.MoveToStartElement(elementName, dictionaryManager.XmlSignatureDictionary.Namespace);
            this.prefix = reader.Prefix;
            bool isEmptyElement = reader.IsEmptyElement;
            algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
            if (string.IsNullOrEmpty(algorithm))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.ID0001, dictionaryManager.XmlSignatureDictionary.Algorithm, reader.LocalName)));
            }
            
            if (algorithm == dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14nWithComments.Value)
            {
                // to include comments in canonicalization, two conditions need to be met
                // 1. the Reference must be an xpointer.
                // 2. the transform must be #withComments
                includeComments = preserveComments && true;
            }
            else if (algorithm == dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n.Value)
            {
                includeComments = false;
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.ID6005, algorithm)));
            }

            reader.Read();
            reader.MoveToContent();

            if (!isEmptyElement)
            {
                if (reader.IsStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace))
                {
                    reader.MoveToStartElement(dictionaryManager.ExclusiveC14NDictionary.InclusiveNamespaces, dictionaryManager.ExclusiveC14NDictionary.Namespace);
                    this.inclusiveListElementPrefix = reader.Prefix;
                    bool emptyElement = reader.IsEmptyElement;
                    // We treat PrefixList as optional Attribute.
                    this.InclusiveNamespacesPrefixList = reader.GetAttribute(dictionaryManager.ExclusiveC14NDictionary.PrefixList, null);
                    reader.Read();
                    if (!emptyElement)
                        reader.ReadEndElement();
                }
                reader.MoveToContent();
                reader.ReadEndElement(); // Transform
            }
        }
Exemplo n.º 28
0
        public void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager)
        {
            reader.MoveToContent();
            reader.MoveToStartElement(XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);
            string prefix = reader.Prefix;

            bool skipReadingTransformEnd = reader.IsEmptyElement;
            reader.ReadStartElement();

            if (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, dictionaryManager.XmlSignatureDictionary.Namespace))
            {

                string algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                // Canonicalization Method can be empty.
                // <elementNOTempty></elementNOTempty>
                // <elementEmpty/>
                bool skipReadingC14End = reader.IsEmptyElement;

                reader.ReadStartElement();

                if (algorithm == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(
                        SR.GetString(SR.RequiredAttributeMissing, dictionaryManager.XmlSignatureDictionary.Algorithm, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod)));
                }

                if (algorithm != this.CanonicalizationAlgorithm)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform)));
                }


                // ReadEndElement() called only if element was not empty
                if (!skipReadingC14End)
                {
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
            }

            // If it was empty, don't read endElement as it was read in ReadStartElement
            if (!skipReadingTransformEnd)
            {
                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
Exemplo n.º 29
0
        public override void ReadFrom(XmlDictionaryReader reader, DictionaryManager dictionaryManager, bool preserveComments)
        {
            reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace);
            this.prefix = reader.Prefix;
            bool isEmptyElement = reader.IsEmptyElement;
            string algorithm = reader.GetAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
            if (algorithm != this.Algorithm)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.GetString(SR.AlgorithmMismatchForTransform)));
            }

            reader.MoveToContent();
            reader.Read();

            if (!isEmptyElement)
            {
                if (reader.IsStartElement(XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace))
                {
                    this.transformationParameters.ReadFrom(reader, dictionaryManager);
                }

                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
Exemplo n.º 30
0
        private static string GetMemberName(XmlDictionaryReader jsonReader)
        {
            string name;
            if (jsonReader.NamespaceURI == ItemElementName && jsonReader.LocalName == ItemElementName)
            {
                // JXML special case for names which aren't valid XML names
                name = jsonReader.GetAttribute(ItemElementName);

                if (name == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SG.GetString(SR.IncorrectJsonFormat)));
                }
            }
            else
            {
                name = jsonReader.Name;
            }

            return name;
        }
Exemplo n.º 31
0
        private static JsonObject CreateObjectWithTypeHint(XmlDictionaryReader jsonReader, ref bool isEmptyElement)
        {
            JsonObject jsonObject = new JsonObject();
            string typeHintAttribute = jsonReader.GetAttribute(TypeHintAttributeName);
            isEmptyElement = jsonReader.IsEmptyElement;
            jsonReader.ReadStartElement();
            SkipWhitespace(jsonReader);
            if (typeHintAttribute != null)
            {
                jsonObject.Add(TypeHintAttributeName, typeHintAttribute);
            }

            return jsonObject;
        }
Exemplo n.º 32
0
        public override void ReadFrom(XmlDictionaryReader reader, TransformFactory transformFactory, DictionaryManager dictionaryManager)
        {
            this.SendSide = false;
            if (reader.CanCanonicalize)
            {
                this.CanonicalStream = new MemoryStream();
                reader.StartCanonicalization(this.CanonicalStream, false, null);
            }

            reader.MoveToStartElement(dictionaryManager.XmlSignatureDictionary.SignedInfo, dictionaryManager.XmlSignatureDictionary.Namespace);
            this.prefix = reader.Prefix;
            this.Id = reader.GetAttribute(dictionaryManager.UtilityDictionary.IdAttribute, null);
            reader.Read();

            ReadCanonicalizationMethod(reader, dictionaryManager);
            ReadSignatureMethod(reader, dictionaryManager);
            while (reader.IsStartElement(dictionaryManager.XmlSignatureDictionary.Reference, dictionaryManager.XmlSignatureDictionary.Namespace))
            {
                Reference reference = new Reference(dictionaryManager);
                reference.ReadFrom(reader, transformFactory, dictionaryManager);
                AddReference(reference);
            }
            reader.ReadEndElement(); // SignedInfo

            if (reader.CanCanonicalize)
                reader.EndCanonicalization();

            string[] inclusivePrefixes = GetInclusivePrefixes();
            if (inclusivePrefixes != null)
            {
                // Clear the canonicalized stream. We cannot use this while inclusive prefixes are
                // specified.
                this.CanonicalStream = null;
                this.context = new Dictionary<string, string>(inclusivePrefixes.Length);
                for (int i = 0; i < inclusivePrefixes.Length; i++)
                {
                    this.context.Add(inclusivePrefixes[i], reader.LookupNamespace(inclusivePrefixes[i]));
                }
            }
        }
Exemplo n.º 33
0
        public static JsonValue JXMLToJsonValue(XmlDictionaryReader jsonReader)
        {
            if (jsonReader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("jsonReader");
            }

            const string RootObjectName = "RootObject";
            Stack<JsonValue> jsonStack = new Stack<JsonValue>();
            string nodeType = null;
            bool isEmptyElement = false;
            JsonValue parent = new JsonObject();
            jsonStack.Push(parent);
            string currentName = RootObjectName;

            try
            {
                MoveToRootNode(jsonReader);
                while (jsonStack.Count > 0 && jsonReader.NodeType != XmlNodeType.None)
                {
                    if (parent is JsonObject && currentName == null)
                    {
                        currentName = GetMemberName(jsonReader);
                    }

                    nodeType = jsonReader.GetAttribute(TypeAttributeName) ?? StringAttributeValue;

                    if (parent is JsonArray)
                    {
                        // For arrays, the element name has to be "item"
                        if (jsonReader.Name != ItemElementName)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SG.GetString(SR.IncorrectJsonFormat)));
                        }
                    }

                    switch (nodeType)
                    {
                        case NullAttributeValue:
                        case BooleanAttributeValue:
                        case StringAttributeValue:
                        case NumberAttributeValue:
                            JsonPrimitive jsonPrimitive = ReadPrimitive(nodeType, jsonReader);
                            InsertJsonValue(jsonStack, ref parent, ref currentName, jsonPrimitive, true);
                            break;
                        case ArrayAttributeValue:
                            JsonArray jsonArray = CreateJsonArray(jsonReader, ref isEmptyElement);
                            InsertJsonValue(jsonStack, ref parent, ref currentName, jsonArray, isEmptyElement);
                            break;
                        case ObjectAttributeValue:
                            JsonObject jsonObject = CreateObjectWithTypeHint(jsonReader, ref isEmptyElement);
                            InsertJsonValue(jsonStack, ref parent, ref currentName, jsonObject, isEmptyElement);
                            break;
                        default:
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SG.GetString(SR.IncorrectJsonFormat)));
                    }

                    while (jsonReader.NodeType == XmlNodeType.EndElement && jsonStack.Count > 0)
                    {
                        jsonReader.Read();
                        SkipWhitespace(jsonReader);
                        jsonStack.Pop();
                        if (jsonStack.Count > 0)
                        {
                            parent = jsonStack.Peek();
                        }
                    }
                }
            }
            catch (XmlException xmlException)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SG.GetString(SR.IncorrectJsonFormat), xmlException));
            }

            if (jsonStack.Count != 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SG.GetString(SR.IncorrectJsonFormat)));
            }

            return parent[RootObjectName];
        }
        public override void ReadXml(XmlDictionaryReader reader, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
        {
            if (reader == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));

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

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

            string authInstance = reader.GetAttribute(dictionary.AuthenticationInstant, null);
            if (string.IsNullOrEmpty(authInstance))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthenticationStatementMissingAuthenticationInstanceOnRead)));
            this.authenticationInstant = DateTime.ParseExact(
                authInstance, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime();

            this.authenticationMethod = reader.GetAttribute(dictionary.AuthenticationMethod, null);
            if (string.IsNullOrEmpty(this.authenticationMethod))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthenticationStatementMissingAuthenticationMethodOnRead)));

            reader.MoveToContent();
            reader.Read();

            if (reader.IsStartElement(dictionary.Subject, dictionary.Namespace))
            {
                SamlSubject subject = new SamlSubject();
                subject.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                base.SamlSubject = subject;
            }
            else
            {
                // Subject is a required element for a Authentication Statement clause.
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthenticationStatementMissingSubject)));
            }

            if (reader.IsStartElement(dictionary.SubjectLocality, dictionary.Namespace))
            {
                this.dnsAddress = reader.GetAttribute(dictionary.SubjectLocalityDNSAddress, null);
                this.ipAddress = reader.GetAttribute(dictionary.SubjectLocalityIPAddress, null);

                if (reader.IsEmptyElement)
                {
                    reader.MoveToContent();
                    reader.Read();
                }
                else
                {
                    reader.MoveToContent();
                    reader.Read();
                    reader.ReadEndElement();
                }
            }

            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(dictionary.AuthorityBinding, dictionary.Namespace))
                {
                    SamlAuthorityBinding binding = new SamlAuthorityBinding();
                    binding.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                    this.authorityBindings.Add(binding);
                }
                else
                {
                    // We do not understand this element.
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.AuthenticationStatement)));
                }
            }

            reader.MoveToContent();
            reader.ReadEndElement();
        }