Skip to content

Commit

Permalink
Polish MultiConcernBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Matasx committed Dec 7, 2024
1 parent 8df505b commit e0b75b9
Showing 1 changed file with 49 additions and 24 deletions.
73 changes: 49 additions & 24 deletions Modules/Authentication/Multi/ApiKeyConcernBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,71 @@

namespace GenHTTP.Modules.Authentication.Multi;

/// <summary>
/// Builder for creating a multi-concern authentication handler.
/// </summary>
public sealed class MultiConcernBuilder : IConcernBuilder
{
#region Fields

private readonly List<IConcernBuilder> _delegatingConcernsBuilders = [];

#endregion

#region Private add functionality

private MultiConcernBuilder AddIfNotNull(IConcernBuilder concernBuilder)
{
if (concernBuilder == null) return this;

_delegatingConcernsBuilders.Add(concernBuilder);
return this;
}

#endregion

#region Functionality

/// <summary>
/// Add nested API concern builder to this multi concern.
/// </summary>
/// <param name="apiKeyBuilder">Nested API key concern builder</param>
public MultiConcernBuilder Add(ApiKeyConcernBuilder apiKeyBuilder)
{
_delegatingConcernsBuilders.Add(apiKeyBuilder);
return this;
}
=> AddIfNotNull(apiKeyBuilder);

public MultiConcernBuilder Add(BasicAuthenticationConcernBuilder apiKeyBuilder)
{
_delegatingConcernsBuilders.Add(apiKeyBuilder);
return this;
}
/// <summary>
/// Add nested API concern builder to this multi concern.
/// </summary>
/// <param name="basicBuilder">Nested Basic concern builder</param>
public MultiConcernBuilder Add(BasicAuthenticationConcernBuilder basicBuilder)
=> AddIfNotNull(basicBuilder);

public MultiConcernBuilder Add(BasicAuthenticationKnownUsersBuilder apiKeyBuilder)
{
_delegatingConcernsBuilders.Add(apiKeyBuilder);
return this;
}
/// <summary>
/// Add nested API concern builder to this multi concern.
/// </summary>
/// <param name="basicKnownUsersBuilder">Nested Basic Known Users concern builder</param>
public MultiConcernBuilder Add(BasicAuthenticationKnownUsersBuilder basicKnownUsersBuilder)
=> AddIfNotNull(basicKnownUsersBuilder);

public MultiConcernBuilder Add(BearerAuthenticationConcernBuilder apiKeyBuilder)
{
_delegatingConcernsBuilders.Add(apiKeyBuilder);
return this;
}
/// <summary>
/// Add nested API concern builder to this multi concern.
/// </summary>
/// <param name="bearerBuilder">Nested Bearer concern builder</param>
public MultiConcernBuilder Add(BearerAuthenticationConcernBuilder bearerBuilder)
=> AddIfNotNull(bearerBuilder);

public MultiConcernBuilder Add(ClientCertificateAuthenticationBuilder apiKeyBuilder)
{
_delegatingConcernsBuilders.Add(apiKeyBuilder);
return this;
}
/// <summary>
/// Add nested API concern builder to this multi concern.
/// </summary>
/// <param name="clientCertificateBuilder">Nested Client Certificate concern builder</param>
public MultiConcernBuilder Add(ClientCertificateAuthenticationBuilder clientCertificateBuilder)
=> AddIfNotNull(clientCertificateBuilder);

/// <summary>
/// Construct the multi concern.
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public IConcern Build(IHandler content)
{
return new MultiConcern(
Expand Down

0 comments on commit e0b75b9

Please sign in to comment.