Skip to content

Commit

Permalink
Merge pull request #203 from ITfoxtec/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Revsgaard authored May 31, 2024
2 parents 95327a0 + 5e5d4d2 commit 9e75ecc
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ public class AttributeConsumingService
{
const string elementName = Saml2MetadataConstants.Message.AttributeConsumingService;

/// <summary>
/// [Required]
/// Language-qualified names for the service.
/// </summary>
[Obsolete("The ServiceName method is deprecated. Please use ServiceNames which is a list of service names.")]
public ServiceName ServiceName { get; set; }
public LocalizedNameType ServiceName { get; set; }

/// <summary>
/// [Required]
/// Language-qualified names for the service.
/// </summary>
public IEnumerable<ServiceName> ServiceNames { get; set; }
public IEnumerable<LocalizedNameType> ServiceNames { get; set; }

/// <summary>
/// [Required]
Expand All @@ -45,12 +49,12 @@ protected IEnumerable<XObject> GetXContent()
{
foreach (var serviceName in ServiceNames)
{
yield return serviceName.ToXElement();
yield return serviceName.ToXElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.ServiceName);
}
}
else
}
else if (ServiceName != null)
{
yield return ServiceName.ToXElement();
yield return ServiceName.ToXElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.ServiceName);
}

if (RequestedAttributes != null)
Expand Down
53 changes: 53 additions & 0 deletions src/ITfoxtec.Identity.Saml2/Schemas/Metadata/LocalizedNameType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Xml.Linq;

namespace ITfoxtec.Identity.Saml2.Schemas.Metadata
{
/// <summary>
/// The LocalizedName element specifies a language specific name.
/// </summary>
public class LocalizedNameType
{
/// <param name="name">The name.</param>
public LocalizedNameType(string name)
{
Name = name;
}

/// <param name="name">The name.</param>
/// <param name="lang">The language.</param>
public LocalizedNameType(string name, string lang) : this(name)
{
Lang = lang;
}

/// <summary>
/// The language.
/// </summary>
public string Lang { get; protected set; }

/// <summary>
/// The Name.
/// </summary>
public string Name { get; protected set; }

public XElement ToXElement(XName elementName)
{
var envelope = new XElement(elementName);

envelope.Add(GetXContent());

return envelope;
}

protected IEnumerable<XObject> GetXContent()
{
if (Lang != null)
{
yield return new XAttribute(XNamespace.Xml + Saml2MetadataConstants.Message.Lang, Lang);
}

yield return new XText(Name);
}
}
}
54 changes: 54 additions & 0 deletions src/ITfoxtec.Identity.Saml2/Schemas/Metadata/LocalizedUriType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace ITfoxtec.Identity.Saml2.Schemas.Metadata
{
/// <summary>
/// The LocalizedUri element specifies a language specific URI.
/// </summary>
public class LocalizedUriType
{
/// <param name="uri">The URI.</param>
public LocalizedUriType(Uri uri)
{
Uri = uri;
}

/// <param name="uri">The URI.</param>
/// <param name="lang">The language.</param>
public LocalizedUriType(Uri uri, string lang) : this(uri)
{
Lang = lang;
}

/// <summary>
/// The language.
/// </summary>
public string Lang { get; protected set; }

/// <summary>
/// The URI.
/// </summary>
public Uri Uri { get; protected set; }

public XElement ToXElement(XName elementName)
{
var envelope = new XElement(elementName);

envelope.Add(GetXContent());

return envelope;
}

protected IEnumerable<XObject> GetXContent()
{
if (Lang != null)
{
yield return new XAttribute(XNamespace.Xml + Saml2MetadataConstants.Message.Lang, Lang);
}

yield return new XText(Uri.OriginalString);
}
}
}
69 changes: 55 additions & 14 deletions src/ITfoxtec.Identity.Saml2/Schemas/Metadata/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace ITfoxtec.Identity.Saml2.Schemas.Metadata
Expand All @@ -12,30 +14,60 @@ public class Organization
{
const string elementName = Saml2MetadataConstants.Message.Organization;

public Organization(string name, string displayName, string url)
public Organization() { }

public Organization(string name, string displayName, Uri url)
{
OrganizationName = name;
OrganizationDisplayName = displayName;
OrganizationURL = url;
OrganizationNames = new[] { new LocalizedNameType(name) };
OrganizationDisplayNames = new[] { new LocalizedNameType(displayName) }; ;
OrganizationURLs = new[] { new LocalizedUriType(url) }; ;
}

public Organization(IEnumerable<LocalizedNameType> names, IEnumerable<LocalizedNameType> displayNames, IEnumerable<LocalizedUriType> urls)
{
OrganizationNames = names;
OrganizationDisplayNames = displayNames;
OrganizationURLs = urls;
}

/// <summary>
/// [Required]
/// Specifies the name of the organization responsible for the SAML entity or role.
/// </summary>
[Obsolete("The OrganizationName method is deprecated. Please use OrganizationNames which is a list of LocalizedNameType's.")]
public string OrganizationName { get { return OrganizationNames?.Select(o => o.Name).FirstOrDefault(); } }

/// <summary>
/// [Required]
/// Specifies the display name of the organization.
/// </summary>
[Obsolete("The OrganizationDisplayName method is deprecated. Please use OrganizationDisplayNames which is a list of LocalizedNameType's.")]
public string OrganizationDisplayName { get { return OrganizationDisplayNames?.Select(o => o.Name).FirstOrDefault(); } }

/// <summary>
/// [Required]
/// Specifies the URL of the organization.
/// </summary>
[Obsolete("The OrganizationURL method is deprecated. Please use OrganizationURLs which is a list of LocalizedUriType's.")]
public string OrganizationURL { get { return OrganizationURLs?.Select(o => o.Uri?.OriginalString).FirstOrDefault(); } }

/// <summary>
/// [Required]
/// Specifies the name of the organization responsible for the SAML entity or role.
/// </summary>
public string OrganizationName { get; protected set; }
public IEnumerable<LocalizedNameType> OrganizationNames { get; set; }

/// <summary>
/// [Required]
/// Specifies the display name of the organization.
/// </summary>
public string OrganizationDisplayName { get; protected set; }
public IEnumerable<LocalizedNameType> OrganizationDisplayNames { get; set; }

/// <summary>
/// [Required]
/// Specifies the URL of the organization.
/// </summary>
public string OrganizationURL { get; protected set; }
public IEnumerable<LocalizedUriType> OrganizationURLs { get; set; }

public XElement ToXElement()
{
Expand All @@ -48,19 +80,28 @@ public XElement ToXElement()

protected IEnumerable<XObject> GetXContent()
{
if (OrganizationName != null)
if (OrganizationNames != null)
{
yield return new XElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.OrganizationName, OrganizationName);
foreach (var name in OrganizationNames)
{
yield return name.ToXElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.OrganizationName);
}
}

if (OrganizationDisplayName != null)
if (OrganizationDisplayNames != null)
{
yield return new XElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.OrganizationDisplayName, OrganizationDisplayName);
foreach (var displayName in OrganizationDisplayNames)
{
yield return displayName.ToXElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.OrganizationDisplayName);
}
}

if (OrganizationURL != null)
if (OrganizationURLs != null)
{
yield return new XElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.OrganizationURL, OrganizationURL);
foreach (var url in OrganizationURLs)
{
yield return url.ToXElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.OrganizationURL);
}
}
}
}
Expand Down
47 changes: 0 additions & 47 deletions src/ITfoxtec.Identity.Saml2/Schemas/Metadata/ServiceName.cs

This file was deleted.

45 changes: 25 additions & 20 deletions test/TestIdPCore/Controllers/MetadataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Security.Cryptography.X509Certificates;

namespace TestWebApp.Controllers
{
Expand All @@ -27,32 +26,38 @@ public IActionResult Index()
entityDescriptor.IdPSsoDescriptor = new IdPSsoDescriptor
{
WantAuthnRequestsSigned = config.SignAuthnRequest,
SigningCertificates = new X509Certificate2[]
{
SigningCertificates =
[
config.SigningCertificate
},
],
//EncryptionCertificates = config.DecryptionCertificates,
SingleSignOnServices = new SingleSignOnService[]
{
SingleSignOnServices =
[
new SingleSignOnService { Binding = ProtocolBindings.HttpRedirect, Location = config.SingleSignOnDestination }
},
SingleLogoutServices = new SingleLogoutService[]
{
],
SingleLogoutServices =
[
new SingleLogoutService { Binding = ProtocolBindings.HttpPost, Location = config.SingleLogoutDestination }
},
ArtifactResolutionServices = new ArtifactResolutionService[]
{
],
ArtifactResolutionServices =
[
new ArtifactResolutionService { Binding = ProtocolBindings.ArtifactSoap, Index = config.ArtifactResolutionService.Index, Location = config.ArtifactResolutionService.Location }
},
NameIDFormats = new Uri[] { NameIdentifierFormats.X509SubjectName },
Attributes = new SamlAttribute[]
{
],
NameIDFormats = [NameIdentifierFormats.X509SubjectName],
Attributes =
[
new SamlAttribute("urn:oid:1.3.6.1.4.1.5923.1.1.1.6", friendlyName: "eduPersonPrincipalName"),
new SamlAttribute("urn:oid:1.3.6.1.4.1.5923.1.1.1.1", new string[] { "member", "student", "employee" })
}
]
};
entityDescriptor.Organization = new Organization("Some Organization", "Some Organization Display Name", "http://some-organization.com");
entityDescriptor.ContactPersons = new[] {
var organization = new Organization(
[new LocalizedNameType("Some Organization", "en")],
[new LocalizedNameType("Some Organization Display Name", "en")],
[new LocalizedUriType(new Uri("http://some-organization.com"), "en")]);

entityDescriptor.Organization = organization;
entityDescriptor.ContactPersons =
[
new ContactPerson(ContactTypes.Administrative)
{
Company = "Some Company",
Expand All @@ -69,7 +74,7 @@ public IActionResult Index()
EmailAddress = "[email protected]",
TelephoneNumber = "22222222",
}
};
];
return new Saml2Metadata(entityDescriptor).CreateMetadata().ToActionResult();
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/TestWebApp/Controllers/MetadataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ActionResult Index()
},
AttributeConsumingServices = new AttributeConsumingService[]
{
new AttributeConsumingService { ServiceName = new ServiceName("Some SP", "en"), RequestedAttributes = CreateRequestedAttributes() }
new AttributeConsumingService { ServiceNames = new LocalizedNameType[] { new LocalizedNameType("Some SP", "en") }, RequestedAttributes = CreateRequestedAttributes() }
},
};
entityDescriptor.ContactPersons = new[] {
Expand Down
Loading

0 comments on commit 9e75ecc

Please sign in to comment.