public void XmlHelpers_AddAttributeIfNotNullOrEmpty_Adds() { var e = new XElement("xml"); e.AddAttributeIfNotNullOrEmpty("attribute", "value"); e.Attribute("attribute").Should().NotBeNull().And.Subject.Value .Should().Be("value"); }
/// <summary> /// Serializes the request to a Xml message. /// </summary> /// <returns>XElement</returns> public XElement ToXElement() { var x = new XElement(Saml2Namespaces.Saml2P + LocalName); x.Add(base.ToXNodes()); x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl); return(x); }
public void XmlHelpers_AddAttributeIfNotNullOrEmpty_HandlesUri() { var e = new XElement("xml"); string uri = "http://some.example.com/"; e.AddAttributeIfNotNullOrEmpty("attribute", new Uri(uri)); e.Attribute("attribute").Should().NotBeNull().And.Subject.Value.Should().Be(uri); }
public void XmlHelpers_AddAttributeIfNotNullOrEmpty_HandlesNamespace() { var e = new XElement("xml"); var ns = XNamespace.Get("someNamespace"); e.AddAttributeIfNotNullOrEmpty(ns + "attribute", ""); e.Attribute(ns + "attribute").Should().BeNull(); }
public override XElement ToXElement() { var xe = new XElement(Saml2Namespaces.Saml2P + "LogoutResponse", new XAttribute("ID", Id.Value), new XAttribute("Version", "2.0"), new XAttribute("IssueInstant", IssueInstant.ToSaml2DateTimeString()), new XElement(Saml2Namespaces.Saml2P + "Status", new XElement(Saml2Namespaces.Saml2P + "StatusCode", new XAttribute("Value", StatusCodeHelper.FromCode(Status))))); if (Issuer != null) { xe.AddFirst(new XElement(Saml2Namespaces.Saml2 + "Issuer", Issuer.Id)); } xe.AddAttributeIfNotNullOrEmpty("InResponseTo", InResponseTo?.Value); xe.AddAttributeIfNotNullOrEmpty("Destination", DestinationUrl?.OriginalString); return(xe); }
private static XElement ToXElement(Saml2AttributeStatement attributeStatement) { var element = new XElement(Saml2Namespaces.Saml2 + "AttributeStatement"); foreach (var attribute in attributeStatement.Attributes) { var attributeElement = new XElement(Saml2Namespaces.Saml2 + "Attribute", new XAttribute("Name", attribute.Name)); attributeElement.AddAttributeIfNotNullOrEmpty("FriendlyName", attribute.FriendlyName); attributeElement.AddAttributeIfNotNullOrEmpty("NameFormat", attribute.NameFormat); attributeElement.AddAttributeIfNotNullOrEmpty("OriginalIssuer", attribute.OriginalIssuer); foreach (var value in attribute.Values) { attributeElement.Add(new XElement(Saml2Namespaces.Saml2 + "AttributeValue", value)); } element.Add(attributeElement); } return(element); }
public void XmlHelpers_AddAttributeIfNotNullOrEmtpy_TimeSpanSerializedCorrectly() { // It might be tempting in the implementation to call value.ToString() // instead of passing in the value. That would make types that have // special XML Serialization formats fail. This test ensures that // nobody takes that shortcut without handling the special cases. var e = new XElement("xml"); e.AddAttributeIfNotNullOrEmpty("attribute", new TimeSpan(2, 17, 32)); e.Attribute("attribute").Should().NotBeNull().And.Subject.Value.Should().Be("PT2H17M32S"); }
public XElement ToXElement() { var x = new XElement(Saml2Namespaces.Saml2P + LocalName); x.Add(base.ToXNodes()); if (Binding.HasValue) { x.AddAttributeIfNotNullOrEmpty("ProtocolBinding", Saml2Binding.Saml2BindingTypeToUri(Binding.Value)); } x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl); x.AddAttributeIfNotNullOrEmpty("AttributeConsumingServiceIndex", AttributeConsumingServiceIndex); if (ForceAuthentication) { x.Add(new XAttribute("ForceAuthn", ForceAuthentication)); } if (Subject != null && Subject.NameId != null && !string.IsNullOrEmpty(Subject.NameId.Value)) { x.Add(Subject.ToXElement()); } AddNameIdPolicy(x); if (RequestedAuthnContext != null && RequestedAuthnContext.ClassRef != null) { x.Add(new XElement(Saml2Namespaces.Saml2P + "RequestedAuthnContext", new XAttribute("Comparison", RequestedAuthnContext.Comparison.ToString().ToLowerInvariant()), // Add the classref as original string to avoid URL normalization // and make sure the emitted value is exactly the configured. new XElement(Saml2Namespaces.Saml2 + "AuthnContextClassRef", RequestedAuthnContext.ClassRef.OriginalString))); } AddScoping(x); return(x); }
public XElement ToXElement() { var x = new XElement(Saml2Namespaces.Saml2P + LocalName); x.Add(base.ToXNodes()); x.AddAttributeIfNotNullOrEmpty("AssertionConsumerServiceURL", AssertionConsumerServiceUrl); x.AddAttributeIfNotNullOrEmpty("AttributeConsumingServiceIndex", AttributeConsumingServiceIndex); AddNameIdPolicy(x); if (RequestedAuthnContext != null && RequestedAuthnContext.ClassRef != null) { x.Add(new XElement(Saml2Namespaces.Saml2P + "RequestedAuthnContext", new XAttribute("Comparison", RequestedAuthnContext.Comparison.ToString().ToLowerInvariant()), // Add the classref as original string to avoid URL normalization // and make sure the emitted value is exactly the configured. new XElement(Saml2Namespaces.Saml2 + "AuthnContextClassRef", RequestedAuthnContext.ClassRef.OriginalString))); } return(x); }
/// <summary> /// Serializes the message into wellformed Xml. /// </summary> /// <returns>string containing the Xml data.</returns> public override string ToXml() { var x = new XElement(Saml2Namespaces.Saml2P + LocalName); x.Add(base.ToXNodes()); var nameId = new XElement(Saml2Namespaces.Saml2 + "NameID", NameId.Value); nameId.AddAttributeIfNotNullOrEmpty("Format", NameId.Format); x.Add(nameId); x.Add(new XElement(Saml2Namespaces.Saml2P + "SessionIndex", SessionIndex)); return(x.ToString()); }
/// <summary> /// Create XElement for the Saml2Scoping. /// </summary> public XElement ToXElement() { var scopingElement = new XElement(Saml2Namespaces.Saml2P + "Scoping"); if (ProxyCount.HasValue && ProxyCount.Value >= 0) { scopingElement.AddAttributeIfNotNullOrEmpty("ProxyCount", ProxyCount); } if (IdPEntries.Count > 0) { scopingElement.Add(new XElement( Saml2Namespaces.Saml2P + "IDPList", IdPEntries.Select(x => x.ToXElement()))); } scopingElement.Add(RequesterIds.Select(x => new XElement(Saml2Namespaces.Saml2P + "RequesterID", x.Id))); return(scopingElement); }
/// <summary> /// Writes out the conditions as an XElement. /// </summary> /// <param name="conditions">Conditions to create xml for.</param> /// <returns>XElement</returns> public static XElement ToXElement(this Saml2Conditions conditions) { if (conditions == null) { throw new ArgumentNullException(nameof(conditions)); } var xml = new XElement(Saml2Namespaces.Saml2 + "Conditions"); xml.AddAttributeIfNotNullOrEmpty("NotOnOrAfter", conditions.NotOnOrAfter?.ToSaml2DateTimeString()); foreach (var ar in conditions.AudienceRestrictions) { xml.Add(new XElement(Saml2Namespaces.Saml2 + "AudienceRestriction", ar.Audiences.Select(a => new XElement(Saml2Namespaces.Saml2 + "Audience", a.OriginalString)))); } return(xml); }