forked from gongxuegit/tiku-backend.net
feat(security): add distributed authorization foundation
This commit is contained in:
21
Tiku.Application/Security/ICapabilityAccessEvaluator.cs
Normal file
21
Tiku.Application/Security/ICapabilityAccessEvaluator.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Tiku.Application.Security;
|
||||
|
||||
public enum CapabilityOperation
|
||||
{
|
||||
Read,
|
||||
Write
|
||||
}
|
||||
|
||||
public interface ICapabilityAccessEvaluator
|
||||
{
|
||||
Task<bool> IsAllowedAsync(
|
||||
Guid tenantId,
|
||||
string moduleCode,
|
||||
CapabilityOperation operation,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task<IReadOnlySet<string>> GetEnabledModulesAsync(
|
||||
Guid tenantId,
|
||||
CapabilityOperation operation = CapabilityOperation.Read,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
23
Tiku.Application/Security/IRedisSecurityStore.cs
Normal file
23
Tiku.Application/Security/IRedisSecurityStore.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace Tiku.Application.Security;
|
||||
|
||||
public sealed record DistributedRateLimitBucket(string Key, int PermitLimit, TimeSpan Window);
|
||||
|
||||
public sealed record DistributedRateLimitResult(bool Allowed, TimeSpan? RetryAfter = null);
|
||||
|
||||
public interface IRedisSecurityStore
|
||||
{
|
||||
bool IsConfigured { get; }
|
||||
|
||||
Task<DistributedRateLimitResult> ConsumeAsync(
|
||||
IReadOnlyCollection<DistributedRateLimitBucket> buckets,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task<bool> PingAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
Task SetInvalidationVersionAsync(
|
||||
string realm,
|
||||
Guid? tenantId,
|
||||
Guid? userId,
|
||||
long version,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -1,16 +1,31 @@
|
||||
namespace Tiku.Application.Security;
|
||||
|
||||
public enum SystemScopeCallerType
|
||||
{
|
||||
Platform,
|
||||
Worker,
|
||||
Migrator,
|
||||
PublicQuestionBank,
|
||||
Test
|
||||
}
|
||||
|
||||
public sealed record SystemScopeRequest(
|
||||
Guid? TargetTenantId,
|
||||
SystemScopeCallerType CallerType,
|
||||
string Caller,
|
||||
string Reason,
|
||||
string CorrelationId);
|
||||
|
||||
public interface ITenantExecutionScope
|
||||
{
|
||||
Task ExecuteAsync(
|
||||
Guid? targetTenantId,
|
||||
string reason,
|
||||
SystemScopeRequest request,
|
||||
Func<IServiceProvider, CancellationToken, Task> operation,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
Task<TResult> ExecuteAsync<TResult>(
|
||||
Guid? targetTenantId,
|
||||
string reason,
|
||||
SystemScopeRequest request,
|
||||
Func<IServiceProvider, CancellationToken, Task<TResult>> operation,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user