diff --git a/DotBased.AspNet.Authority/Attributes/ProtectAttribute.cs b/DotBased.AspNet.Authority/Attributes/ProtectAttribute.cs index 13394b8..58775b1 100644 --- a/DotBased.AspNet.Authority/Attributes/ProtectAttribute.cs +++ b/DotBased.AspNet.Authority/Attributes/ProtectAttribute.cs @@ -1,7 +1,7 @@ namespace DotBased.AspNet.Authority.Attributes; /// -/// Indicates that the property should be protected. +/// Indicates to protect the property before saving to the repository. /// [AttributeUsage(AttributeTargets.Property)] public class ProtectAttribute : Attribute diff --git a/DotBased.AspNet.Authority/DotBased.AspNet.Authority.csproj b/DotBased.AspNet.Authority/DotBased.AspNet.Authority.csproj index 14ddfd0..b99e760 100644 --- a/DotBased.AspNet.Authority/DotBased.AspNet.Authority.csproj +++ b/DotBased.AspNet.Authority/DotBased.AspNet.Authority.csproj @@ -19,7 +19,6 @@ - diff --git a/DotBased.AspNet.Authority/Interfaces/ISecurityVersionRepository.cs b/DotBased.AspNet.Authority/Interfaces/ISecurityVersionRepository.cs new file mode 100644 index 0000000..866d22c --- /dev/null +++ b/DotBased.AspNet.Authority/Interfaces/ISecurityVersionRepository.cs @@ -0,0 +1,7 @@ +namespace DotBased.AspNet.Authority.Interfaces; + +public interface ISecurityVersionRepository +{ + public Task GetSecurityVersionAsync(TRepositoryObject obj); + +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Interfaces/IUserRepository.cs b/DotBased.AspNet.Authority/Interfaces/IUserRepository.cs index 0bc7ad3..c7035a3 100644 --- a/DotBased.AspNet.Authority/Interfaces/IUserRepository.cs +++ b/DotBased.AspNet.Authority/Interfaces/IUserRepository.cs @@ -1,6 +1,8 @@ namespace DotBased.AspNet.Authority.Interfaces; -public interface IUserRepository +public interface IUserRepository : IVersionRepository, ISecurityVersionRepository where TUser : class where TId : IEquatable { - + public Task GetUserByIdAsync(TId id); + + public Task GetUserIdAsync(TUser user); } \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Interfaces/IVersionRepository.cs b/DotBased.AspNet.Authority/Interfaces/IVersionRepository.cs new file mode 100644 index 0000000..b88ec89 --- /dev/null +++ b/DotBased.AspNet.Authority/Interfaces/IVersionRepository.cs @@ -0,0 +1,6 @@ +namespace DotBased.AspNet.Authority.Interfaces; + +public interface IVersionRepository +{ + public Task GetVersionAsync(TRepositoryObject obj); +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityAttribute.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityAttribute.cs new file mode 100644 index 0000000..dc4e5b5 --- /dev/null +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityAttribute.cs @@ -0,0 +1,25 @@ +namespace DotBased.AspNet.Authority.Models.Authority; + +public class AuthorityAttribute +{ + public AuthorityAttribute(string attributeKey, string bound) : this() + { + AttributeKey = attributeKey; + BoundId = bound; + } + + public AuthorityAttribute() + { + + } + + public string AttributeKey { get; set; } // ClaimType/Authority.attribute.enabled + + public string BoundId { get; set; } // Bound to User, Group, Role id + + public string? AttributeValue { get; set; } + + public string? Type { get; set; } // AspNet.Claim.Role/Property/Data.JSON, Data.Raw, Data.Base64 etc. + + public long Version { get; set; } +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs new file mode 100644 index 0000000..df010e8 --- /dev/null +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs @@ -0,0 +1,26 @@ +namespace DotBased.AspNet.Authority.Models.Authority; + +public class AuthorityGroup : AuthorityGroup +{ + public AuthorityGroup(string name) : this() + { + Name = name; + } + + public AuthorityGroup() + { + Id = Guid.NewGuid(); + CreatedDate = DateTime.Now; + } +} + +public abstract class AuthorityGroup where TKey : IEquatable +{ + public TKey Id { get; set; } + + public string? Name { get; set; } + + public long Version { get; set; } + + public DateTime CreatedDate { get; set; } +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs new file mode 100644 index 0000000..90ccee5 --- /dev/null +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs @@ -0,0 +1,28 @@ +namespace DotBased.AspNet.Authority.Models.Authority; + +public class AuthorityRole : AuthorityRole +{ + public AuthorityRole(string name) : this() + { + Name = name; + } + + public AuthorityRole() + { + Id = Guid.NewGuid(); + CreatedDate = DateTime.Now; + } +} + +public abstract class AuthorityRole where TKey : IEquatable +{ + public TKey Id { get; set; } + + public string? Name { get; set; } + + public long Version { get; set; } + + public DateTime CreatedDate { get; set; } + + public override string ToString() => Name ?? string.Empty; +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityUser.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityUser.cs index 6c4f8a5..7ed6f9b 100644 --- a/DotBased.AspNet.Authority/Models/Authority/AuthorityUser.cs +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityUser.cs @@ -1,10 +1,52 @@ +using DotBased.AspNet.Authority.Attributes; + namespace DotBased.AspNet.Authority.Models.Authority; -public class AuthorityUser : AuthorityUserBase +public class AuthorityUser : AuthorityUser { + public AuthorityUser(string userName) : this() + { + UserName = userName; + } + public AuthorityUser() { Id = Guid.NewGuid(); CreatedDate = DateTime.Now; } +} + +public abstract class AuthorityUser where TKey : IEquatable +{ + public TKey Id { get; set; } + + public bool Enabled { get; set; } + + public bool Locked { get; set; } + + public DateTime LockedDate { get; set; } + + public string? UserName { get; set; } + + public string? PasswordHash { get; set; } + + public DateTime CreatedDate { get; set; } + + public bool TwoFactorEnabled { get; set; } + + public long Version { get; set; } + + public long SecurityVersion { get; set; } + + [Protect] + public string? EmailAddress { get; set; } + + public bool EmailConfirmed { get; set; } + + [Protect] + public string? PhoneNumber { get; set; } + + public bool PhoneNumberConfirmed { get; set; } + + public override string ToString() => UserName ?? EmailAddress ?? string.Empty; } \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityUserBase.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityUserBase.cs deleted file mode 100644 index 83b8166..0000000 --- a/DotBased.AspNet.Authority/Models/Authority/AuthorityUserBase.cs +++ /dev/null @@ -1,35 +0,0 @@ -using DotBased.AspNet.Authority.Attributes; - -namespace DotBased.AspNet.Authority.Models.Authority; - -public abstract class AuthorityUserBase where TKey : IEquatable -{ - public TKey Id { get; set; } - - public bool Enabled { get; set; } - - public bool Locked { get; set; } - - public string UserName { get; set; } - - public string PasswordHash { get; set; } - - public DateTime CreatedDate { get; set; } - - public bool TwoFactorEnabled { get; set; } - - public string ConcurrencyStamp { get; set; } - public string SecurityStamp { get; set; } - - - [Protect] - public string EmailAddress { get; set; } - - public bool EmailConfirmed { get; set; } - - [Protect] - public string PhoneNumber { get; set; } - - public bool PhoneNumberConfirmed { get; set; } - -} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Repositories/AuthorityRepository.cs b/DotBased.AspNet.Authority/Repositories/AuthorityRepository.cs new file mode 100644 index 0000000..239c114 --- /dev/null +++ b/DotBased.AspNet.Authority/Repositories/AuthorityRepository.cs @@ -0,0 +1,6 @@ +namespace DotBased.AspNet.Authority.Repositories; + +public class AuthorityRepository // Inherit the repository interfaces? +{ + +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Services/AuthorityService.cs b/DotBased.AspNet.Authority/Services/AuthorityService.cs index 9f90f61..2c61b55 100644 --- a/DotBased.AspNet.Authority/Services/AuthorityService.cs +++ b/DotBased.AspNet.Authority/Services/AuthorityService.cs @@ -2,5 +2,5 @@ namespace DotBased.AspNet.Authority.Services; public class AuthorityService { - + public long GenerateVersion() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); } \ No newline at end of file