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(); }
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")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; string attribute = reader.GetAttribute(samlDictionary.AuthenticationInstant, null); if (string.IsNullOrEmpty(attribute)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthenticationStatementMissingAuthenticationInstanceOnRead"))); } this.authenticationInstant = DateTime.ParseExact(attribute, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime(); this.authenticationMethod = reader.GetAttribute(samlDictionary.AuthenticationMethod, null); if (string.IsNullOrEmpty(this.authenticationMethod)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthenticationStatementMissingAuthenticationMethodOnRead"))); } reader.MoveToContent(); reader.Read(); if (!reader.IsStartElement(samlDictionary.Subject, samlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAuthenticationStatementMissingSubject"))); } SamlSubject subject = new SamlSubject(); subject.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver); base.SamlSubject = subject; if (reader.IsStartElement(samlDictionary.SubjectLocality, samlDictionary.Namespace)) { this.dnsAddress = reader.GetAttribute(samlDictionary.SubjectLocalityDNSAddress, null); this.ipAddress = reader.GetAttribute(samlDictionary.SubjectLocalityIPAddress, null); if (reader.IsEmptyElement) { reader.MoveToContent(); reader.Read(); } else { reader.MoveToContent(); reader.Read(); reader.ReadEndElement(); } } while (reader.IsStartElement()) { if (!reader.IsStartElement(samlDictionary.AuthorityBinding, samlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.AuthenticationStatement }))); } SamlAuthorityBinding item = new SamlAuthorityBinding(); item.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver); this.authorityBindings.Add(item); } reader.MoveToContent(); reader.ReadEndElement(); }
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(); }