-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5c8b26
commit 4211c17
Showing
23 changed files
with
298 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Sustainsys.Saml2.Xml; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Sustainsys.Saml2.Saml; | ||
|
||
/// <summary> | ||
/// A Saml assertion | ||
/// </summary> | ||
public class Assertion | ||
{ | ||
/// <summary> | ||
/// Id of the assertion | ||
/// </summary> | ||
public string Id { get; set; } = XmlHelpers.CreateId(); | ||
|
||
/// <summary> | ||
/// Issuer of the assertion. | ||
/// </summary> | ||
public NameId Issuer { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// Version. Must be 2.0 | ||
/// </summary> | ||
public string Version { get; set; } = "2.0"; | ||
|
||
/// <summary> | ||
/// Isssue instance of the assertion | ||
/// </summary> | ||
public DateTime IssueInstance { get; set; } = DateTime.UtcNow; | ||
|
||
/// <summary> | ||
/// Subject of the assertion | ||
/// </summary> | ||
public Subject Subject { get; set; } = default!; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/Sustainsys.Saml2/Serialization/SamlXmlReader.Assertion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Sustainsys.Saml2.Saml; | ||
using Sustainsys.Saml2.Xml; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using static Sustainsys.Saml2.Constants; | ||
|
||
namespace Sustainsys.Saml2.Serialization; | ||
|
||
public partial class SamlXmlReader | ||
{ | ||
/// <summary> | ||
/// Create an empty Assertion instances | ||
/// </summary> | ||
/// <returns>Assertion</returns> | ||
protected virtual Assertion CreateAssertion() => new(); | ||
|
||
/// <inheritdoc/> | ||
public Assertion ReadAssertion( | ||
XmlTraverser source, | ||
Action<ReadErrorInspectorContext<Assertion>>? errorInspector = null) | ||
{ | ||
var assertion = ReadAssertion(source); | ||
|
||
CallErrorInspector(errorInspector, assertion, source); | ||
|
||
source.ThrowOnErrors(); | ||
|
||
return assertion; | ||
} | ||
|
||
/// <summary> | ||
/// Read an <see cref="Assertion"/> | ||
/// </summary> | ||
/// <param name="source">Xml Traverser to read from</param> | ||
protected virtual Assertion ReadAssertion(XmlTraverser source) | ||
{ | ||
var assertion = CreateAssertion(); | ||
|
||
if (source.EnsureName(Namespaces.SamlUri, Elements.Assertion)) | ||
{ | ||
ReadAttributes(source, assertion); | ||
ReadElements(source.GetChildren(), assertion); | ||
|
||
source.MoveNext(true); | ||
} | ||
|
||
return assertion; | ||
} | ||
|
||
/// <summary> | ||
/// Read attributes of an assertion | ||
/// </summary> | ||
/// <param name="source">Xml Traverser to read from</param> | ||
/// <param name="assertion"></param> | ||
protected virtual void ReadAttributes(XmlTraverser source, Assertion assertion) | ||
{ | ||
assertion.Id = source.GetRequiredAttribute(Attributes.ID); | ||
assertion.IssueInstance = source.GetRequiredDateTimeAttribute(Attributes.IssueInstant); | ||
assertion.Version = source.GetRequiredAttribute(Attributes.Version); | ||
} | ||
|
||
/// <summary> | ||
/// Read elements of an assertion | ||
/// </summary> | ||
/// <param name="source"></param> | ||
/// <param name="assertion"></param> | ||
protected virtual void ReadElements(XmlTraverser source, Assertion assertion) | ||
{ | ||
source.MoveNext(); | ||
|
||
if (source.EnsureName(Namespaces.SamlUri, Elements.Issuer)) | ||
{ | ||
assertion.Issuer = ReadNameId(source); | ||
source.MoveNext(); | ||
} | ||
|
||
// Status is optional on XML schema level, but Core 2.3.3. says that | ||
// "an assertion without a subject has no defined meaning in this specification." | ||
if (source.EnsureName(Namespaces.SamlUri, Elements.Subject)) | ||
{ | ||
assertion.Subject = ReadSubject(source); | ||
source.MoveNext(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.