Skip to content

Commit

Permalink
fixed formatting to use tabs and not spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
RagingKore committed May 16, 2024
1 parent 399b7fc commit 0f884b4
Show file tree
Hide file tree
Showing 31 changed files with 975 additions and 1,041 deletions.
108 changes: 54 additions & 54 deletions src/EventStore.Plugins/Authentication/AuthenticationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,69 @@
namespace EventStore.Plugins.Authentication;

public abstract class AuthenticationRequest {
/// <summary>
/// Whether a valid client certificate was supplied with the request
/// </summary>
public readonly bool HasValidClientCertificate;
/// <summary>
/// Whether a valid client certificate was supplied with the request
/// </summary>
public readonly bool HasValidClientCertificate;

/// <summary>
/// The Identifier for the source that this request came from
/// </summary>
public readonly string Id;
/// <summary>
/// The Identifier for the source that this request came from
/// </summary>
public readonly string Id;

/// <summary>
/// The name of the principal for the request
/// </summary>
public readonly string Name;
/// <summary>
/// The name of the principal for the request
/// </summary>
public readonly string Name;

/// <summary>
/// The supplied password for the request
/// </summary>
public readonly string SuppliedPassword;
/// <summary>
/// The supplied password for the request
/// </summary>
public readonly string SuppliedPassword;

/// <summary>
/// All supplied authentication tokens for the request
/// </summary>
public readonly IReadOnlyDictionary<string, string> Tokens;
/// <summary>
/// All supplied authentication tokens for the request
/// </summary>
public readonly IReadOnlyDictionary<string, string> Tokens;

protected AuthenticationRequest(string? id, IReadOnlyDictionary<string, string>? tokens) {
ArgumentNullException.ThrowIfNull(id);
ArgumentNullException.ThrowIfNull(tokens);
protected AuthenticationRequest(string? id, IReadOnlyDictionary<string, string>? tokens) {
ArgumentNullException.ThrowIfNull(id);
ArgumentNullException.ThrowIfNull(tokens);

Id = id;
Tokens = tokens;
Name = GetToken("uid") ?? "";
SuppliedPassword = GetToken("pwd") ?? "";
HasValidClientCertificate = GetToken("client-certificate") != null;
}
Id = id;
Tokens = tokens;
Name = GetToken("uid") ?? "";
SuppliedPassword = GetToken("pwd") ?? "";
HasValidClientCertificate = GetToken("client-certificate") != null;
}

/// <summary>
/// Gets the token corresponding to
/// <param name="key" />
/// .
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string? GetToken(string key) => Tokens.GetValueOrDefault(key);
/// <summary>
/// Gets the token corresponding to
/// <param name="key" />
/// .
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string? GetToken(string key) => Tokens.GetValueOrDefault(key);

/// <summary>
/// The request is unauthorized
/// </summary>
public abstract void Unauthorized();
/// <summary>
/// The request is unauthorized
/// </summary>
public abstract void Unauthorized();

/// <summary>
/// The request was successfully authenticated
/// </summary>
/// <param name="principal">The <see cref="ClaimsPrincipal" /> of the authenticated request</param>
public abstract void Authenticated(ClaimsPrincipal principal);
/// <summary>
/// The request was successfully authenticated
/// </summary>
/// <param name="principal">The <see cref="ClaimsPrincipal" /> of the authenticated request</param>
public abstract void Authenticated(ClaimsPrincipal principal);

/// <summary>
/// An error occurred during authentication
/// </summary>
public abstract void Error();
/// <summary>
/// An error occurred during authentication
/// </summary>
public abstract void Error();

/// <summary>
/// The authentication provider is not yet ready to service the request
/// </summary>
public abstract void NotReady();
/// <summary>
/// The authentication provider is not yet ready to service the request
/// </summary>
public abstract void NotReady();
}
103 changes: 50 additions & 53 deletions src/EventStore.Plugins/Authentication/HttpAuthenticationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,57 @@
namespace EventStore.Plugins.Authentication;

public enum HttpAuthenticationRequestStatus {
None,
Error,
NotReady,
Unauthenticated,
Authenticated
None,
Error,
NotReady,
Unauthenticated,
Authenticated
}

public class HttpAuthenticationRequest : AuthenticationRequest {
readonly CancellationTokenRegistration _cancellationRegister;
readonly TaskCompletionSource<(HttpAuthenticationRequestStatus, ClaimsPrincipal?)> _tcs;

public HttpAuthenticationRequest(HttpContext context, string authToken) : this(context,
new Dictionary<string, string> {
["jwt"] = authToken
}) {
}

public HttpAuthenticationRequest(HttpContext context, string name, string suppliedPassword) :
this(context, new Dictionary<string, string> {
["uid"] = name,
["pwd"] = suppliedPassword
}) {
}

HttpAuthenticationRequest(HttpContext context, IReadOnlyDictionary<string, string> tokens) : base(
context.TraceIdentifier, tokens) {
_tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
_cancellationRegister = context.RequestAborted.Register(Cancel);
}

public static HttpAuthenticationRequest CreateWithValidCertificate(HttpContext context, string name, X509Certificate2 clientCertificate) {
return new(context, new Dictionary<string, string> {
["uid"] = name,
["client-certificate"] = clientCertificate.ExportCertificatePem()
});
}

void Cancel() {
_tcs.TrySetCanceled();
_cancellationRegister.Dispose();
}

public override void Unauthorized() =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.Unauthenticated, default));

public override void Authenticated(ClaimsPrincipal principal) =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.Authenticated, principal));

public override void Error() =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.Error, default));

public override void NotReady() =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.NotReady, default));

public Task<(HttpAuthenticationRequestStatus, ClaimsPrincipal?)> AuthenticateAsync() =>
_tcs.Task;
readonly CancellationTokenRegistration _cancellationRegister;
readonly TaskCompletionSource<(HttpAuthenticationRequestStatus, ClaimsPrincipal?)> _tcs;

public HttpAuthenticationRequest(HttpContext context, string authToken) : this(context,
new Dictionary<string, string> {
["jwt"] = authToken
}) { }

public HttpAuthenticationRequest(HttpContext context, string name, string suppliedPassword) :
this(context, new Dictionary<string, string> {
["uid"] = name,
["pwd"] = suppliedPassword
}) { }

HttpAuthenticationRequest(HttpContext context, IReadOnlyDictionary<string, string> tokens) : base(
context.TraceIdentifier, tokens) {
_tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
_cancellationRegister = context.RequestAborted.Register(Cancel);
}

public static HttpAuthenticationRequest CreateWithValidCertificate(HttpContext context, string name, X509Certificate2 clientCertificate) => new(context,
new Dictionary<string, string> {
["uid"] = name,
["client-certificate"] = clientCertificate.ExportCertificatePem()
});

void Cancel() {
_tcs.TrySetCanceled();
_cancellationRegister.Dispose();
}

public override void Unauthorized() =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.Unauthenticated, default));

public override void Authenticated(ClaimsPrincipal principal) =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.Authenticated, principal));

public override void Error() =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.Error, default));

public override void NotReady() =>
_tcs.TrySetResult((HttpAuthenticationRequestStatus.NotReady, default));

public Task<(HttpAuthenticationRequestStatus, ClaimsPrincipal?)> AuthenticateAsync() =>
_tcs.Task;
}
16 changes: 8 additions & 8 deletions src/EventStore.Plugins/Authentication/IAuthenticationPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace EventStore.Plugins.Authentication;

public interface IAuthenticationPlugin {
string Name { get; }
string Version { get; }
string CommandLineName { get; }
string Name { get; }
string Version { get; }
string CommandLineName { get; }

/// <summary>
/// Creates an authentication provider factory for the authentication plugin
/// </summary>
/// <param name="authenticationConfigPath">The path to the configuration file for the authentication plugin</param>
IAuthenticationProviderFactory GetAuthenticationProviderFactory(string authenticationConfigPath);
/// <summary>
/// Creates an authentication provider factory for the authentication plugin
/// </summary>
/// <param name="authenticationConfigPath">The path to the configuration file for the authentication plugin</param>
IAuthenticationProviderFactory GetAuthenticationProviderFactory(string authenticationConfigPath);
}
46 changes: 23 additions & 23 deletions src/EventStore.Plugins/Authentication/IAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
namespace EventStore.Plugins.Authentication;

public interface IAuthenticationProvider : IPlugableComponent {
/// <summary>
/// Initialize the AuthenticationProvider. Event Store will wait until this task completes before becoming ready.
/// </summary>
Task Initialize();
/// <summary>
/// Initialize the AuthenticationProvider. Event Store will wait until this task completes before becoming ready.
/// </summary>
Task Initialize();

/// <summary>
/// Authenticate an AuthenticationRequest. Call the appropriate method on <see cref="AuthenticationRequest" />
/// depending on whether the request succeeded, failed, or errored.
/// </summary>
/// <param name="authenticationRequest"></param>
void Authenticate(AuthenticationRequest authenticationRequest);
/// <summary>
/// Authenticate an AuthenticationRequest. Call the appropriate method on <see cref="AuthenticationRequest" />
/// depending on whether the request succeeded, failed, or errored.
/// </summary>
/// <param name="authenticationRequest"></param>
void Authenticate(AuthenticationRequest authenticationRequest);

/// <summary>
/// Get public properties which may be required for the authentication flow.
/// </summary>
IEnumerable<KeyValuePair<string, string>> GetPublicProperties();
/// <summary>
/// Get public properties which may be required for the authentication flow.
/// </summary>
IEnumerable<KeyValuePair<string, string>> GetPublicProperties();

/// <summary>
/// Create any required endpoints.
/// </summary>
/// <param name="endpointRouteBuilder"></param>
void ConfigureEndpoints(IEndpointRouteBuilder endpointRouteBuilder);
/// <summary>
/// Create any required endpoints.
/// </summary>
/// <param name="endpointRouteBuilder"></param>
void ConfigureEndpoints(IEndpointRouteBuilder endpointRouteBuilder);

/// <summary>
/// Get supported authentication schemes.
/// </summary>
IReadOnlyList<string> GetSupportedAuthenticationSchemes();
/// <summary>
/// Get supported authentication schemes.
/// </summary>
IReadOnlyList<string> GetSupportedAuthenticationSchemes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace EventStore.Plugins.Authentication;

public interface IAuthenticationProviderFactory {
/// <summary>
/// Build an AuthenticationProvider for the authentication plugin
/// </summary>
/// <param name="logFailedAuthenticationAttempts">
/// Whether the Authentication Provider should log failed authentication
/// attempts
/// </param>
/// <param name="logger">The <see cref="ILogger" /> to use when logging in the plugin</param>
IAuthenticationProvider Build(bool logFailedAuthenticationAttempts, ILogger logger);
/// <summary>
/// Build an AuthenticationProvider for the authentication plugin
/// </summary>
/// <param name="logFailedAuthenticationAttempts">
/// Whether the Authentication Provider should log failed authentication attempts
/// </param>
/// <param name="logger">The <see cref="ILogger" /> to use when logging in the plugin</param>
IAuthenticationProvider Build(bool logFailedAuthenticationAttempts, ILogger logger);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace EventStore.Plugins.Authentication;

public interface IHttpAuthenticationProvider {
/// <summary>
/// Return a unique name used to externally identify the authentication provider.
/// </summary>
string Name { get; }
/// <summary>
/// Return a unique name used to externally identify the authentication provider.
/// </summary>
string Name { get; }

bool Authenticate(HttpContext context, out HttpAuthenticationRequest request);
bool Authenticate(HttpContext context, out HttpAuthenticationRequest request);
}
16 changes: 8 additions & 8 deletions src/EventStore.Plugins/Authorization/IAuthorizationPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace EventStore.Plugins.Authorization;

public interface IAuthorizationPlugin {
string Name { get; }
string Version { get; }
string CommandLineName { get; }
string Name { get; }
string Version { get; }
string CommandLineName { get; }

/// <summary>
/// Creates an authorization provider factory for the authorization plugin
/// </summary>
/// <param name="authorizationConfigPath">The path to the configuration file for the authorization plugin</param>
IAuthorizationProviderFactory GetAuthorizationProviderFactory(string authorizationConfigPath);
/// <summary>
/// Creates an authorization provider factory for the authorization plugin
/// </summary>
/// <param name="authorizationConfigPath">The path to the configuration file for the authorization plugin</param>
IAuthorizationProviderFactory GetAuthorizationProviderFactory(string authorizationConfigPath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace EventStore.Plugins.Authorization;

public interface IAuthorizationProvider : IPlugableComponent {
/// <summary>
/// Check whether the provided <see cref="ClaimsPrincipal" /> has the rights to perform the <see cref="Operation" />
/// </summary>
ValueTask<bool> CheckAccessAsync(ClaimsPrincipal cp, Operation operation, CancellationToken ct);
/// <summary>
/// Check whether the provided <see cref="ClaimsPrincipal" /> has the rights to perform the <see cref="Operation" />
/// </summary>
ValueTask<bool> CheckAccessAsync(ClaimsPrincipal cp, Operation operation, CancellationToken ct);
}
Loading

0 comments on commit 0f884b4

Please sign in to comment.