public virtual SamlAssertion LoadAssertion(XmlDictionaryReader reader, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
        {
            if (reader == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");

            SamlAssertion assertion = new SamlAssertion();
            assertion.ReadXml(reader, this, keyInfoSerializer, outOfBandTokenResolver);

            return assertion;
        }
        public virtual SamlAssertion LoadAssertion(XmlDictionaryReader reader, SecurityTokenSerializer keyInfoSerializer, SecurityTokenResolver outOfBandTokenResolver)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }
            SamlAssertion assertion = new SamlAssertion();

            assertion.ReadXml(reader, this, keyInfoSerializer, outOfBandTokenResolver);
            return(assertion);
        }
Exemple #3
0
        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"));
            }

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

            // SAML Advice is an optional element and all its child elements are optional
            // too. So we may have an empty saml:Advice element in the saml token.
            if (reader.IsEmptyElement)
            {
                // Just issue a read for the empty element.
                reader.MoveToContent();
                reader.Read();
                return;
            }

            reader.MoveToContent();
            reader.Read();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(dictionary.AssertionIdReference, dictionary.Namespace))
                {
                    reader.MoveToContent();
                    this.assertionIdReferences.Add(reader.ReadString());
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
                else if (reader.IsStartElement(dictionary.Assertion, dictionary.Namespace))
                {
                    SamlAssertion assertion = new SamlAssertion();
                    assertion.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                    this.assertions.Add(assertion);
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.Advice.Value)));
                }
            }

            reader.MoveToContent();
            reader.ReadEndElement();
        }
Exemple #4
0
        public virtual void ReadXml(XmlDictionaryReader reader,
                                    SamlSerializer samlSerializer,
                                    SecurityTokenSerializer keyInfoSerializer,
                                    SecurityTokenResolver resolver)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (samlSerializer == null)
            {
                throw new ArgumentNullException("samlSerializer");
            }
            references.Clear();
            assertions.Clear();

            reader.ReadStartElement("Evidence", SamlConstants.Namespace);
            for (reader.MoveToContent();
                 reader.NodeType == XmlNodeType.Element;
                 reader.MoveToContent())
            {
                if (reader.NamespaceURI != SamlConstants.Namespace)
                {
                    throw new SecurityTokenException(String.Format("Invalid SAML Evidence element: element '{0}' in namespace '{1}' is unexpected.", reader.LocalName, reader.NamespaceURI));
                }
                switch (reader.LocalName)
                {
                case "Assertion":
                    SamlAssertion a = new SamlAssertion();
                    a.ReadXml(reader, samlSerializer, keyInfoSerializer, resolver);
                    assertions.Add(a);
                    break;

                case "AssertionIDReference":
                    references.Add(reader.ReadElementContentAsString());
                    break;

                default:
                    throw new SecurityTokenException(String.Format("Invalid SAML Evidence element: SAML element '{0}' is unexpected.", reader.LocalName));
                }
            }
            reader.ReadEndElement();

            if (references.Count == 0 && assertions.Count == 0)
            {
                throw new SecurityTokenException("At least either one of AssertionIDReference or Assertion must exist in SAML Evidence.");
            }
        }
Exemple #5
0
        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.IsEmptyElement)
            {
                reader.MoveToContent();
                reader.Read();
            }
            else
            {
                reader.MoveToContent();
                reader.Read();
                while (reader.IsStartElement())
                {
                    if (!reader.IsStartElement(samlDictionary.AssertionIdReference, samlDictionary.Namespace))
                    {
                        if (!reader.IsStartElement(samlDictionary.Assertion, samlDictionary.Namespace))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.Advice.Value })));
                        }
                        SamlAssertion item = new SamlAssertion();
                        item.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                        this.assertions.Add(item);
                    }
                    else
                    {
                        reader.MoveToContent();
                        this.assertionIdReferences.Add(reader.ReadString());
                        reader.MoveToContent();
                        reader.ReadEndElement();
                        continue;
                    }
                }
                reader.MoveToContent();
                reader.ReadEndElement();
            }
        }
Exemple #6
0
        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"));
            }

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

            reader.MoveToContent();
            reader.Read();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(dictionary.AssertionIdReference, dictionary.Namespace))
                {
                    reader.MoveToContent();
                    this.assertionIdReferences.Add(reader.ReadString());
                    reader.ReadEndElement();
                }
                else if (reader.IsStartElement(dictionary.Assertion, dictionary.Namespace))
                {
                    SamlAssertion assertion = new SamlAssertion();
                    assertion.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                    this.assertions.Add(assertion);
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.Evidence.Value)));
                }
            }

            if ((this.assertionIdReferences.Count == 0) && (this.assertions.Count == 0))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertionOnRead)));
            }

            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"));

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

            reader.MoveToContent();
            reader.Read();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(dictionary.AssertionIdReference, dictionary.Namespace))
                {
                    reader.MoveToContent();
                    this.assertionIdReferences.Add(reader.ReadString());
                    reader.ReadEndElement();
                }
                else if (reader.IsStartElement(dictionary.Assertion, dictionary.Namespace))
                {
                    SamlAssertion assertion = new SamlAssertion();
                    assertion.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                    this.assertions.Add(assertion);
                }
                else
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.Evidence.Value)));
            }

            if ((this.assertionIdReferences.Count == 0) && (this.assertions.Count == 0))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLEvidenceShouldHaveOneAssertionOnRead)));

            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"));

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

            // SAML Advice is an optional element and all its child elements are optional 
            // too. So we may have an empty saml:Advice element in the saml token.
            if (reader.IsEmptyElement)
            {
                // Just issue a read for the empty element.
                reader.MoveToContent();
                reader.Read();
                return;
            }

            reader.MoveToContent();
            reader.Read();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(dictionary.AssertionIdReference, dictionary.Namespace))
                {
                    reader.MoveToContent();
                    this.assertionIdReferences.Add(reader.ReadString());
                    reader.MoveToContent();
                    reader.ReadEndElement();
                }
                else if (reader.IsStartElement(dictionary.Assertion, dictionary.Namespace))
                {
                    SamlAssertion assertion = new SamlAssertion();
                    assertion.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
                    this.assertions.Add(assertion);
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.Advice.Value)));
                }
            }

            reader.MoveToContent();
            reader.ReadEndElement();
        }
Exemple #9
0
		public virtual void ReadXml (XmlDictionaryReader reader,
			SamlSerializer samlSerializer,
			SecurityTokenSerializer keyInfoTokenSerializer,
			SecurityTokenResolver outOfBandTokenResolver)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");
			if (samlSerializer == null)
				throw new ArgumentNullException ("samlSerializer");
			reader.ReadStartElement ("Advice", SamlConstants.Namespace);
			for (reader.MoveToContent ();
			     reader.NodeType == XmlNodeType.Element;
			     reader.MoveToContent ()) {
				if (reader.NamespaceURI != SamlConstants.Namespace)
					throw new SecurityTokenException (String.Format ("Invalid SAML Advice element: element '{0}' in namespace '{1}' is unexpected.", reader.LocalName, reader.NamespaceURI));
				switch (reader.LocalName) {
				case "Assertion":
					SamlAssertion a = new SamlAssertion ();
					a.ReadXml (reader, samlSerializer, keyInfoTokenSerializer, outOfBandTokenResolver);
					assertions.Add (a);
					break;
				case "AssertionIDReference":
					idrefs.Add (reader.ReadElementContentAsString ());
					break;
				default:
					throw new SecurityTokenException (String.Format ("Invalid SAML Advice element: SAML element '{0}' is unexpected.", reader.LocalName));
				}
			}
			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;
     reader.MoveToContent();
     reader.Read();
     while (reader.IsStartElement())
     {
         if (!reader.IsStartElement(samlDictionary.AssertionIdReference, samlDictionary.Namespace))
         {
             if (!reader.IsStartElement(samlDictionary.Assertion, samlDictionary.Namespace))
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.Evidence.Value })));
             }
             SamlAssertion item = new SamlAssertion();
             item.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver);
             this.assertions.Add(item);
         }
         else
         {
             reader.MoveToContent();
             this.assertionIdReferences.Add(reader.ReadString());
             reader.ReadEndElement();
             continue;
         }
     }
     if ((this.assertionIdReferences.Count == 0) && (this.assertions.Count == 0))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLEvidenceShouldHaveOneAssertionOnRead")));
     }
     reader.MoveToContent();
     reader.ReadEndElement();
 }