From 8e54fdc184bbd1bc8f1c4b8d4fff40725449fd6b Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 13 Apr 2023 01:51:53 +0300 Subject: [PATCH] Added security entities --- .../DbContexts/NetworkDbContext.cs | 4 ++++ .../Security/PermissionConfiguration.cs | 16 ++++++++++++++++ .../Security/PermissionHierarchyConfiguration.cs | 15 +++++++++++++++ .../UserRoleAuthorizationConfiguration.cs | 15 +++++++++++++++ .../Entities/Security/Permission.cs | 13 +++++++++++++ .../Entities/Security/PermissionHierarchy.cs | 9 +++++++++ .../Entities/Security/UserRoleAuthorization.cs | 10 ++++++++++ 7 files changed, 82 insertions(+) create mode 100644 src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionConfiguration.cs create mode 100644 src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionHierarchyConfiguration.cs create mode 100644 src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/UserRoleAuthorizationConfiguration.cs create mode 100644 src/api/NetworkResurrector.Api.Domain/Entities/Security/Permission.cs create mode 100644 src/api/NetworkResurrector.Api.Domain/Entities/Security/PermissionHierarchy.cs create mode 100644 src/api/NetworkResurrector.Api.Domain/Entities/Security/UserRoleAuthorization.cs diff --git a/src/api/NetworkResurrector.Api.Domain.Data/DbContexts/NetworkDbContext.cs b/src/api/NetworkResurrector.Api.Domain.Data/DbContexts/NetworkDbContext.cs index 3471159..3aec565 100644 --- a/src/api/NetworkResurrector.Api.Domain.Data/DbContexts/NetworkDbContext.cs +++ b/src/api/NetworkResurrector.Api.Domain.Data/DbContexts/NetworkDbContext.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration; using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Power; +using NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security; using NetworkResurrector.Api.Domain.Entities; namespace NetworkResurrector.Api.Domain.Data.DbContexts @@ -26,6 +27,9 @@ namespace NetworkResurrector.Api.Domain.Data.DbContexts modelBuilder.ApplyConfiguration(new PowerActionPerformerConfiguration()); modelBuilder.ApplyConfiguration(new PowerActionConfigurationEf()); modelBuilder.ApplyConfiguration(new MachineAgentConfiguration()); + modelBuilder.ApplyConfiguration(new PermissionConfiguration()); + modelBuilder.ApplyConfiguration(new PermissionHierarchyConfiguration()); + modelBuilder.ApplyConfiguration(new UserRoleAuthorizationConfiguration()); } } } diff --git a/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionConfiguration.cs b/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionConfiguration.cs new file mode 100644 index 0000000..cf808cc --- /dev/null +++ b/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionConfiguration.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using NetworkResurrector.Api.Domain.Entities.Security; + +namespace NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security +{ + class PermissionConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("Permission").HasKey(key => key.PermissionId); + builder.Property(z => z.PermissionId).ValueGeneratedOnAdd(); + builder.HasMany(z => z.Children).WithOne().HasForeignKey(z => z.ParentPermissionId); + } + } +} diff --git a/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionHierarchyConfiguration.cs b/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionHierarchyConfiguration.cs new file mode 100644 index 0000000..a02be43 --- /dev/null +++ b/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/PermissionHierarchyConfiguration.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using NetworkResurrector.Api.Domain.Entities.Security; + +namespace NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security +{ + class PermissionHierarchyConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("PermissionHierarchy").HasKey(p => new { p.ParentPermissionId, p.ChildPermissionId }); + builder.HasOne(z => z.Child).WithMany().HasForeignKey(p => p.ChildPermissionId); + } + } +} diff --git a/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/UserRoleAuthorizationConfiguration.cs b/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/UserRoleAuthorizationConfiguration.cs new file mode 100644 index 0000000..348c2c6 --- /dev/null +++ b/src/api/NetworkResurrector.Api.Domain.Data/EntityTypeConfiguration/Security/UserRoleAuthorizationConfiguration.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using NetworkResurrector.Api.Domain.Entities.Security; + +namespace NetworkResurrector.Api.Domain.Data.EntityTypeConfiguration.Security +{ + class UserRoleAuthorizationConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("UserRoleAuthorization").HasKey(z => new { z.UserRoleId, z.PermissionId }); + builder.HasOne(z => z.Permission).WithMany().HasForeignKey(z => z.PermissionId); + } + } +} diff --git a/src/api/NetworkResurrector.Api.Domain/Entities/Security/Permission.cs b/src/api/NetworkResurrector.Api.Domain/Entities/Security/Permission.cs new file mode 100644 index 0000000..645081c --- /dev/null +++ b/src/api/NetworkResurrector.Api.Domain/Entities/Security/Permission.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace NetworkResurrector.Api.Domain.Entities.Security +{ + public class Permission + { + public int PermissionId { get; set; } + public string PermissionCode { get; set; } + public string PermissionName { get; set; } + public string PermissionDescription { get; set; } + public ICollection Children { get; set; } + } +} diff --git a/src/api/NetworkResurrector.Api.Domain/Entities/Security/PermissionHierarchy.cs b/src/api/NetworkResurrector.Api.Domain/Entities/Security/PermissionHierarchy.cs new file mode 100644 index 0000000..41a7f3e --- /dev/null +++ b/src/api/NetworkResurrector.Api.Domain/Entities/Security/PermissionHierarchy.cs @@ -0,0 +1,9 @@ +namespace NetworkResurrector.Api.Domain.Entities.Security +{ + public class PermissionHierarchy + { + public int ParentPermissionId { get; set; } + public int ChildPermissionId { get; set; } + public Permission Child { get; set; } + } +} diff --git a/src/api/NetworkResurrector.Api.Domain/Entities/Security/UserRoleAuthorization.cs b/src/api/NetworkResurrector.Api.Domain/Entities/Security/UserRoleAuthorization.cs new file mode 100644 index 0000000..6f209d8 --- /dev/null +++ b/src/api/NetworkResurrector.Api.Domain/Entities/Security/UserRoleAuthorization.cs @@ -0,0 +1,10 @@ +namespace NetworkResurrector.Api.Domain.Entities.Security +{ + public class UserRoleAuthorization + { + public int UserRoleId { get; set; } + public int PermissionId { get; set; } + public bool Active { get; set; } + public Permission Permission { get; set; } + } +}