Skip to content

Commit

Permalink
First steps on Assertion validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersAbel committed Feb 3, 2024
1 parent 07d4a9a commit af19aa6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/Sustainsys.Saml2/Saml/SamlAssertion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainsys.Saml2.Saml;

/// <summary>
/// A Saml assertion
/// </summary>
public class SamlAssertion
{
/// <summary>
/// Issuer of the assertion.
/// </summary>
public NameId Issuer { get; set; } = default!;
}
32 changes: 32 additions & 0 deletions src/Sustainsys.Saml2/Validation/ISamlAssertionValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Sustainsys.Saml2.Saml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainsys.Saml2.Validation;

/// <summary>
/// Validates an asseriton
/// </summary>
public interface ISamlAssertionValidator
{
/// <summary>
/// Validate a Saml assertion
/// </summary>
/// <param name="assertion"></param>
/// <param name="parameters"></param>
void Validate(SamlAssertion assertion, SamlAssertionValidationParameters parameters);
}

/// <summary>
/// DTO carrying parameters for Saml assertion validation
/// </summary>
public class SamlAssertionValidationParameters
{
/// <summary>
/// Valid issuer of the response and assertions
/// </summary>
public NameId? ValidIssuer { get; set; }
}
10 changes: 8 additions & 2 deletions src/Sustainsys.Saml2/Validation/ISamlResponseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public interface ISamlResponseValidator
public class SamlResponseValidationParameters
{
/// <summary>
/// Valid issuer of the response and assertions
/// Validation parameters for assertions embedded in the response.
/// </summary>
public NameId? ValidIssuer { get; set; }
public required SamlAssertionValidationParameters AssertionValidationParameters { get; set; }

/// <summary>
/// Valid issuer of the response and assertions - returns the ValidIssuer
/// of the embedded SamlAssertionValidationParameters to ensure they are the same.
/// </summary>
public NameId? ValidIssuer { get => AssertionValidationParameters.ValidIssuer; }
}
22 changes: 22 additions & 0 deletions src/Sustainsys.Saml2/Validation/SamlAssertionValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Sustainsys.Saml2.Saml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sustainsys.Saml2.Validation;

/// <summary>
/// Saml Assertion validator
/// </summary>
public class SamlAssertionValidator : ISamlAssertionValidator
{
/// <inheritdoc/>
public void Validate(
SamlAssertion assertion,
SamlAssertionValidationParameters parameters)
{
// TODO: Remember to validate issuer.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ SamlResponse CreateSamlResponse() =>
SamlResponseValidationParameters CreateValidationParameters() =>
new SamlResponseValidationParameters()
{
ValidIssuer = "https://idp.example.com/Saml2"
AssertionValidationParameters = new()
{
ValidIssuer = "https://idp.example.com/Saml2"
}
};

// The happy path that should just validate the default response
Expand Down

0 comments on commit af19aa6

Please sign in to comment.