Reimplementing Authorization system
This commit is contained in:
16
DotBased.ASP.Authentication/BasedAuthenticationBuilder.cs
Normal file
16
DotBased.ASP.Authentication/BasedAuthenticationBuilder.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace DotBased.ASP.Authentication;
|
||||
|
||||
public class BasedAuthenticationBuilder
|
||||
{
|
||||
public BasedAuthenticationBuilder(Type authRepository)
|
||||
{
|
||||
if (authRepository.IsValueType)
|
||||
{
|
||||
throw new ArgumentException("Type cannot be a value type!", nameof(authRepository));
|
||||
}
|
||||
|
||||
AuthenticationRepositoryType = authRepository;
|
||||
}
|
||||
|
||||
public Type AuthenticationRepositoryType { get; }
|
||||
}
|
||||
34
DotBased.ASP.Authentication/BasedAuthenticationExtensions.cs
Normal file
34
DotBased.ASP.Authentication/BasedAuthenticationExtensions.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using DotBased.ASP.Authentication.Configuration;
|
||||
using DotBased.ASP.Authentication.Repositories;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DotBased.ASP.Authentication;
|
||||
|
||||
public static class BasedAuthenticationExtensions
|
||||
{
|
||||
public static BasedAuthenticationBuilder AddBasedAuthentication(this IServiceCollection services, Action<AuthenticationConfiguration>? configurationAction)
|
||||
{
|
||||
/*
|
||||
* Add services
|
||||
* - Validators
|
||||
* - Managers
|
||||
* - Services
|
||||
*/
|
||||
if (configurationAction != null)
|
||||
{
|
||||
services.Configure(configurationAction);
|
||||
}
|
||||
|
||||
return new BasedAuthenticationBuilder(typeof(BasedAuthenticationBuilder));
|
||||
}
|
||||
|
||||
public static BasedAuthenticationBuilder AddRepository<TRepository>(this BasedAuthenticationBuilder builder)
|
||||
{
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static BasedAuthenticationBuilder SeedData<TRepository>(this BasedAuthenticationBuilder builder, Action<TRepository> seeder) where TRepository : RepositoryBase
|
||||
{
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
||||
namespace DotBased.ASP.Authentication;
|
||||
|
||||
public class BasedAuthenticationStateProvider : AuthenticationStateProvider
|
||||
{
|
||||
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace DotBased.ASP.Authentication.Configuration;
|
||||
|
||||
public class AuthenticationConfiguration
|
||||
{
|
||||
public CacheConfiguration Cache { get; set; } = new();
|
||||
public LockoutConfiguration Lockout { get; set; } = new();
|
||||
public PasswordConfiguration Password { get; set; } = new();
|
||||
public UserConfiguration User { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Configuration;
|
||||
|
||||
public class CacheConfiguration
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Configuration;
|
||||
|
||||
public class LockoutConfiguration
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Configuration;
|
||||
|
||||
public class PasswordConfiguration
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Configuration;
|
||||
|
||||
public class UserConfiguration
|
||||
{
|
||||
|
||||
}
|
||||
6
DotBased.ASP.Authentication/Providers/IStateProvider.cs
Normal file
6
DotBased.ASP.Authentication/Providers/IStateProvider.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Providers;
|
||||
|
||||
public interface IStateProvider
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public interface IAttributeRepository
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public interface IAuthenticationRepository
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public interface IGroupRepository
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public interface IRoleRepository
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public interface ISessionRepository
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public interface IUserRepository
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DotBased.ASP.Authentication.Repositories;
|
||||
|
||||
public abstract class RepositoryBase : IAuthenticationRepository, IAttributeRepository, IGroupRepository, ISessionRepository, IUserRepository
|
||||
{
|
||||
|
||||
}
|
||||
17
DotBased.ASP.Authentication/SecurityManager.cs
Normal file
17
DotBased.ASP.Authentication/SecurityManager.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using DotBased.ASP.Authentication.Configuration;
|
||||
using DotBased.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DotBased.ASP.Authentication;
|
||||
|
||||
public class SecurityManager
|
||||
{
|
||||
public SecurityManager(IServiceProvider services, IOptions<AuthenticationConfiguration>? config)
|
||||
{
|
||||
_services = services;
|
||||
Configuration = config?.Value ?? new AuthenticationConfiguration();
|
||||
}
|
||||
private ILogger _logger = LogService.RegisterLogger<SecurityManager>();
|
||||
private IServiceProvider _services;
|
||||
public AuthenticationConfiguration Configuration { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user