public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { this.CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Attribute, samlDictionary.Namespace); writer.WriteStartAttribute(samlDictionary.AttributeName, null); writer.WriteString(this.name); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.AttributeNamespace, null); writer.WriteString(this.nameSpace); writer.WriteEndAttribute(); for (int i = 0; i < this.attributeValues.Count; i++) { if (this.attributeValues[i] == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(System.IdentityModel.SR.GetString("SAMLAttributeValueCannotBeNull")); } writer.WriteElementString(samlDictionary.PreferredPrefix.Value, samlDictionary.AttributeValue, samlDictionary.Namespace, this.attributeValues[i]); } writer.WriteEndElement(); }
public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AudienceRestrictionCondition, dictionary.Namespace); for (int i = 0; i < this.audiences.Count; i++) { writer.WriteElementString(dictionary.Audience, dictionary.Namespace, this.audiences[i].AbsoluteUri); } writer.WriteEndElement(); }
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 WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Evidence.Value, dictionary.Namespace.Value); for (int i = 0; i < this.assertionIdReferences.Count; i++) { writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AssertionIdReference, dictionary.Namespace); writer.WriteString(this.assertionIdReferences[i]); writer.WriteEndElement(); } for (int i = 0; i < this.assertions.Count; i++) { this.assertions[i].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Advice, samlDictionary.Namespace); for (int i = 0; i < this.assertionIdReferences.Count; i++) { writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AssertionIdReference, samlDictionary.Namespace); writer.WriteString(this.assertionIdReferences[i]); writer.WriteEndElement(); } for (int j = 0; j < this.assertions.Count; j++) { this.assertions[j].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
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; if (reader.IsStartElement(dictionary.Action, dictionary.Namespace)) { // The Namespace attribute is optional. this.ns = reader.GetAttribute(dictionary.ActionNamespaceAttribute, null); reader.MoveToContent(); this.action = reader.ReadString(); if (string.IsNullOrEmpty(this.action)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLActionNameRequiredOnRead))); } reader.MoveToContent(); reader.ReadEndElement(); } }
public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { this.CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AuthorizationDecisionStatement, samlDictionary.Namespace); writer.WriteStartAttribute(samlDictionary.Decision, null); writer.WriteString(this.accessDecision.ToString()); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.Resource, null); writer.WriteString(this.resource); writer.WriteEndAttribute(); base.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer); foreach (SamlAction action in this.actions) { action.WriteXml(writer, samlSerializer, keyInfoSerializer); } if (this.evidence != null) { this.evidence.WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Action, dictionary.Namespace); if (this.ns != null) { writer.WriteStartAttribute(dictionary.ActionNamespaceAttribute, null); writer.WriteString(this.ns); writer.WriteEndAttribute(); } writer.WriteString(this.action); writer.WriteEndElement(); }
public virtual void 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 WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Conditions, samlDictionary.Namespace); if (this.notBefore != System.IdentityModel.SecurityUtils.MinUtcDateTime) { writer.WriteStartAttribute(samlDictionary.NotBefore, null); writer.WriteString(this.notBefore.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", DateTimeFormatInfo.InvariantInfo)); writer.WriteEndAttribute(); } if (this.notOnOrAfter != System.IdentityModel.SecurityUtils.MaxUtcDateTime) { writer.WriteStartAttribute(samlDictionary.NotOnOrAfter, null); writer.WriteString(this.notOnOrAfter.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", DateTimeFormatInfo.InvariantInfo)); writer.WriteEndAttribute(); } for (int i = 0; i < this.conditions.Count; i++) { this.conditions[i].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
public override void 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; if (!reader.IsStartElement(dictionary.DoNotCacheCondition, dictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.DoNotCacheCondition.Value))); } // saml:DoNotCacheCondition is a empty element. So just issue a read for // the empty element. if (reader.IsEmptyElement) { reader.MoveToContent(); reader.Read(); return; } reader.MoveToContent(); reader.Read(); 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; if (!reader.IsStartElement(samlDictionary.DoNotCacheCondition, samlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLBadSchema", new object[] { samlDictionary.DoNotCacheCondition.Value }))); } if (reader.IsEmptyElement) { reader.MoveToContent(); reader.Read(); } else { reader.MoveToContent(); reader.Read(); 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; 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 { // SAML Subject is a required Attribute Statement clause. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeStatementMissingSubjectOnRead))); } while (reader.IsStartElement()) { if (reader.IsStartElement(dictionary.Attribute, dictionary.Namespace)) { // SAML Attribute is a extensibility point. So ask the SAML serializer // to load this part. SamlAttribute attribute = samlSerializer.LoadAttribute(reader, keyInfoSerializer, outOfBandTokenResolver); if (attribute == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadAttribute))); } this.attributes.Add(attribute); } else { break; } } if (this.attributes.Count == 0) { // Each Attribute statement should have at least one attribute. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeStatementMissingAttributeOnRead))); } 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; string authKind = reader.GetAttribute(dictionary.AuthorityKind, null); if (string.IsNullOrEmpty(authKind)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthorityBindingMissingAuthorityKindOnRead))); string[] authKindParts = authKind.Split(':'); if (authKindParts.Length > 2) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthorityBindingInvalidAuthorityKind))); string localName; string prefix; string nameSpace; if (authKindParts.Length == 2) { prefix = authKindParts[0]; localName = authKindParts[1]; } else { prefix = String.Empty; localName = authKindParts[0]; } nameSpace = reader.LookupNamespace(prefix); this.authorityKind = new XmlQualifiedName(localName, nameSpace); this.binding = reader.GetAttribute(dictionary.Binding, null); if (string.IsNullOrEmpty(this.binding)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthorityBindingMissingBindingOnRead))); this.location = reader.GetAttribute(dictionary.Location, null); if (string.IsNullOrEmpty(this.location)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAuthorityBindingMissingLocationOnRead))); if (reader.IsEmptyElement) { reader.MoveToContent(); reader.Read(); } else { reader.MoveToContent(); reader.Read(); reader.ReadEndElement(); } }
public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AuthenticationStatement, dictionary.Namespace); writer.WriteStartAttribute(dictionary.AuthenticationMethod, null); writer.WriteString(this.authenticationMethod); writer.WriteEndAttribute(); writer.WriteStartAttribute(dictionary.AuthenticationInstant, null); writer.WriteString(this.authenticationInstant.ToString(SamlConstants.GeneratedDateTimeFormat, CultureInfo.InvariantCulture)); writer.WriteEndAttribute(); this.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer); if ((this.ipAddress != null) || (this.dnsAddress != null)) { writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.SubjectLocality, dictionary.Namespace); if (this.ipAddress != null) { writer.WriteStartAttribute(dictionary.SubjectLocalityIPAddress, null); writer.WriteString(this.ipAddress); writer.WriteEndAttribute(); } if (this.dnsAddress != null) { writer.WriteStartAttribute(dictionary.SubjectLocalityDNSAddress, null); writer.WriteString(this.dnsAddress); writer.WriteEndAttribute(); } writer.WriteEndElement(); } for (int i = 0; i < this.authorityBindings.Count; i++) { this.authorityBindings[i].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
public 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; string time = reader.GetAttribute(dictionary.NotBefore, null); if (!string.IsNullOrEmpty(time)) { this.notBefore = DateTime.ParseExact( time, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime(); } time = reader.GetAttribute(dictionary.NotOnOrAfter, null); if (!string.IsNullOrEmpty(time)) { this.notOnOrAfter = DateTime.ParseExact( time, SamlConstants.AcceptedDateTimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None).ToUniversalTime(); } // Saml Conditions element is an optional element and all its child element // are optional as well. So we can have a empty <saml:Conditions /> element // in a valid Saml token. if (reader.IsEmptyElement) { // Just issue a read to read the Empty element. reader.MoveToContent(); reader.Read(); return; } reader.MoveToContent(); reader.Read(); while (reader.IsStartElement()) { SamlCondition condition = samlSerializer.LoadCondition(reader, keyInfoSerializer, outOfBandTokenResolver); if (condition == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLUnableToLoadCondtion))); } this.conditions.Add(condition); } reader.MoveToContent(); reader.ReadEndElement(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { this.CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; try { writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Assertion, samlDictionary.Namespace); writer.WriteStartAttribute(samlDictionary.MajorVersion, null); writer.WriteValue(SamlConstants.MajorVersionValue); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.MinorVersion, null); writer.WriteValue(SamlConstants.MinorVersionValue); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.AssertionId, null); writer.WriteString(this.assertionId); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.Issuer, null); writer.WriteString(this.issuer); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.IssueInstant, null); writer.WriteString(this.issueInstant.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture)); writer.WriteEndAttribute(); if (this.conditions != null) { this.conditions.WriteXml(writer, samlSerializer, keyInfoSerializer); } if (this.advice != null) { this.advice.WriteXml(writer, samlSerializer, keyInfoSerializer); } for (int i = 0; i < this.statements.Count; i++) { this.statements[i].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("SAMLTokenNotSerialized"), exception)); } }
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(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { this.CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Subject, samlDictionary.Namespace); if (this.name != null) { writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.NameIdentifier, samlDictionary.Namespace); if (this.nameFormat != null) { writer.WriteStartAttribute(samlDictionary.NameIdentifierFormat, null); writer.WriteString(this.nameFormat); writer.WriteEndAttribute(); } if (this.nameQualifier != null) { writer.WriteStartAttribute(samlDictionary.NameIdentifierNameQualifier, null); writer.WriteString(this.nameQualifier); writer.WriteEndAttribute(); } writer.WriteString(this.name); writer.WriteEndElement(); } if (this.confirmationMethods.Count > 0) { writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.SubjectConfirmation, samlDictionary.Namespace); foreach (string str in this.confirmationMethods) { writer.WriteElementString(samlDictionary.SubjectConfirmationMethod, samlDictionary.Namespace, str); } if (!string.IsNullOrEmpty(this.confirmationData)) { writer.WriteElementString(samlDictionary.SubjectConfirmationData, samlDictionary.Namespace, this.confirmationData); } if (this.securityKeyIdentifier != null) { SamlSerializer.WriteSecurityKeyIdentifier(XmlDictionaryWriter.CreateDictionaryWriter(writer), this.securityKeyIdentifier, keyInfoSerializer); } writer.WriteEndElement(); } writer.WriteEndElement(); }
public 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; this.name = reader.GetAttribute(dictionary.AttributeName, null); if (string.IsNullOrEmpty(this.name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeMissingNameAttributeOnRead))); } this.nameSpace = reader.GetAttribute(dictionary.AttributeNamespace, null); if (string.IsNullOrEmpty(this.nameSpace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeMissingNamespaceAttributeOnRead))); } this.claimType = string.IsNullOrEmpty(this.nameSpace) ? this.name : this.nameSpace + "/" + this.name; reader.MoveToContent(); reader.Read(); while (reader.IsStartElement(dictionary.AttributeValue, dictionary.Namespace)) { // We will load all Attributes as a string value by default. string attrValue = reader.ReadString(); this.attributeValues.Add(attrValue); reader.MoveToContent(); reader.ReadEndElement(); } if (this.attributeValues.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAttributeShouldHaveOneValue))); } reader.MoveToContent(); reader.ReadEndElement(); }
public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.DoNotCacheCondition, samlDictionary.Namespace); writer.WriteEndElement(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } #pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null. SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AuthorityBinding, dictionary.Namespace); string prefix = null; if (!string.IsNullOrEmpty(this.authorityKind.Namespace)) { writer.WriteAttributeString(String.Empty, dictionary.NamespaceAttributePrefix.Value, null, this.authorityKind.Namespace); prefix = writer.LookupPrefix(this.authorityKind.Namespace); } writer.WriteStartAttribute(dictionary.AuthorityKind, null); if (string.IsNullOrEmpty(prefix)) { writer.WriteString(this.authorityKind.Name); } else { writer.WriteString(prefix + ":" + this.authorityKind.Name); } writer.WriteEndAttribute(); writer.WriteStartAttribute(dictionary.Location, null); writer.WriteString(this.location); writer.WriteEndAttribute(); writer.WriteStartAttribute(dictionary.Binding, null); writer.WriteString(this.binding); writer.WriteEndAttribute(); writer.WriteEndElement(); }
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; reader.MoveToContent(); reader.Read(); while (reader.IsStartElement()) { if (reader.IsStartElement(dictionary.Audience, dictionary.Namespace)) { reader.MoveToContent(); string audience = reader.ReadString(); if (string.IsNullOrEmpty(audience)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAudienceRestrictionInvalidAudienceValueOnRead))); } this.audiences.Add(new Uri(audience)); reader.MoveToContent(); reader.ReadEndElement(); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLBadSchema, dictionary.AudienceRestrictionCondition.Value))); } } if (this.audiences.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.SAMLAudienceRestrictionShouldHaveOneAudienceOnRead))); } 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.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(); } }
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")); } 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(); } }
public override void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { this.CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AuthenticationStatement, samlDictionary.Namespace); writer.WriteStartAttribute(samlDictionary.AuthenticationMethod, null); writer.WriteString(this.authenticationMethod); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.AuthenticationInstant, null); writer.WriteString(this.authenticationInstant.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture)); writer.WriteEndAttribute(); base.SamlSubject.WriteXml(writer, samlSerializer, keyInfoSerializer); if ((this.ipAddress != null) || (this.dnsAddress != null)) { writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.SubjectLocality, samlDictionary.Namespace); if (this.ipAddress != null) { writer.WriteStartAttribute(samlDictionary.SubjectLocalityIPAddress, null); writer.WriteString(this.ipAddress); writer.WriteEndAttribute(); } if (this.dnsAddress != null) { writer.WriteStartAttribute(samlDictionary.SubjectLocalityDNSAddress, null); writer.WriteString(this.dnsAddress); writer.WriteEndAttribute(); } writer.WriteEndElement(); } for (int i = 0; i < this.authorityBindings.Count; i++) { this.authorityBindings[i].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
public DictionaryManager() { _samlDictionary = CoreWCF.XD.SamlDictionary; _sigantureDictionary = CoreWCF.XD.XmlSignatureDictionary; _utilityDictionary = CoreWCF.XD.UtilityDictionary; _exclusiveC14NDictionary = CoreWCF.XD.ExclusiveC14NDictionary; _securityAlgorithmDictionary = CoreWCF.XD.SecurityAlgorithmDictionary; _parentDictionary = CoreWCF.XD.Dictionary; _securityJan2004Dictionary = CoreWCF.XD.SecurityJan2004Dictionary; _securityJanXXX2005Dictionary = CoreWCF.XD.SecurityXXX2005Dictionary; _secureConversationFeb2005Dictionary = CoreWCF.XD.SecureConversationFeb2005Dictionary; _trustFeb2005Dictionary = CoreWCF.XD.TrustFeb2005Dictionary; _xmlEncryptionDictionary = CoreWCF.XD.XmlEncryptionDictionary; // These 3 are factored into a seperate dictionary in ServiceModel under DXD. _secureConversationDec2005Dictionary = DXD.SecureConversationDec2005Dictionary; _securityAlgorithmDec2005Dictionary = DXD.SecurityAlgorithmDec2005Dictionary; _trustDec2005Dictionary = DXD.TrustDec2005Dictionary; }
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; reader.MoveToContent(); reader.Read(); if (!reader.IsStartElement(samlDictionary.Subject, samlDictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAttributeStatementMissingSubjectOnRead"))); } SamlSubject subject = new SamlSubject(); subject.ReadXml(reader, samlSerializer, keyInfoSerializer, outOfBandTokenResolver); base.SamlSubject = subject; while (reader.IsStartElement()) { if (!reader.IsStartElement(samlDictionary.Attribute, samlDictionary.Namespace)) { break; } SamlAttribute item = samlSerializer.LoadAttribute(reader, keyInfoSerializer, outOfBandTokenResolver); if (item == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLUnableToLoadAttribute"))); } this.attributes.Add(item); } if (this.attributes.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(System.IdentityModel.SR.GetString("SAMLAttributeStatementMissingAttributeOnRead"))); } reader.MoveToContent(); reader.ReadEndElement(); }
public DictionaryManager(ServiceModelDictionary parentDictionary) { SamlDictionary = new SamlDictionary(parentDictionary); XmlSignatureDictionary = new XmlSignatureDictionary(parentDictionary); UtilityDictionary = new UtilityDictionary(parentDictionary); ExclusiveC14NDictionary = new ExclusiveC14NDictionary(parentDictionary); SecurityAlgorithmDictionary = new SecurityAlgorithmDictionary(parentDictionary); SecurityJan2004Dictionary = new SecurityJan2004Dictionary(parentDictionary); SecurityJanXXX2005Dictionary = new SecurityXXX2005Dictionary(parentDictionary); SecureConversationFeb2005Dictionary = new SecureConversationFeb2005Dictionary(parentDictionary); TrustFeb2005Dictionary = new TrustFeb2005Dictionary(parentDictionary); XmlEncryptionDictionary = new XmlEncryptionDictionary(parentDictionary); ParentDictionary = parentDictionary; // These 3 are factored into a seperate dictionary in ServiceModel under DXD. // ServiceModel should set these seperately using the property setters. SecureConversationDec2005Dictionary = DXD.SecureConversationDec2005Dictionary; SecurityAlgorithmDec2005Dictionary = DXD.SecurityAlgorithmDec2005Dictionary; TrustDec2005Dictionary = DXD.TrustDec2005Dictionary; }