Skip to content

Commit

Permalink
ASP.NET Core Identity refactoring. (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgernand authored Mar 16, 2023
1 parent 9c00db7 commit 3059784
Show file tree
Hide file tree
Showing 127 changed files with 3,210 additions and 1,301 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,8 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# SQLite database files.
*.db-shm
*.db-wal
*.db
36 changes: 22 additions & 14 deletions AspNetCore.Authorization.Permissions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{24143346-BEA0-4E8E-9249-17FF05C9772F}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -23,13 +24,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Authorization.Pe
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Authorization.Permissions.Abstractions", "src\AspNetCore.Authorization.Permissions.Abstractions\AspNetCore.Authorization.Permissions.Abstractions.csproj", "{188E0288-2D1F-4618-A8DC-8AAF6281A713}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Authorization.Permissions.Identity", "src\AspNetCore.Authorization.Permissions.Identity\AspNetCore.Authorization.Permissions.Identity.csproj", "{F5E8F68F-1DB2-40A0-8071-6B6D2D2F7EC5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Identity", "Identity", "{38E0E64A-6A46-47C7-A169-24A6069D80E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore", "src\AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore\AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore.csproj", "{FC53BA36-7FE5-4D3B-944B-CD0F34FD0320}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleTenant", "samples\SampleTenant\SampleTenant.csproj", "{D1117618-BB2A-4FD0-9C88-9512B9AFC76D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Identity.Permissions", "src\AspNetCore.Identity.Permissions\AspNetCore.Identity.Permissions.csproj", "{30A8E652-AD3F-42B8-AEDB-133660992475}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Identity.Permissions.EntityFrameworkCore", "src\AspNetCore.Identity.Permissions.EntityFrameworkCore\AspNetCore.Identity.Permissions.EntityFrameworkCore.csproj", "{99DA5DAF-7F69-4F23-BE79-A2595ACFC849}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleTenant", "samples\SampleTenant\SampleTenant.csproj", "{D1117618-BB2A-4FD0-9C88-9512B9AFC76D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Identity.Permissions.Core", "src\AspNetCore.Identity.Permissions.Core\AspNetCore.Identity.Permissions.Core.csproj", "{525124A3-58D5-4301-A898-967D999CFB61}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -53,18 +56,22 @@ Global
{188E0288-2D1F-4618-A8DC-8AAF6281A713}.Debug|Any CPU.Build.0 = Debug|Any CPU
{188E0288-2D1F-4618-A8DC-8AAF6281A713}.Release|Any CPU.ActiveCfg = Release|Any CPU
{188E0288-2D1F-4618-A8DC-8AAF6281A713}.Release|Any CPU.Build.0 = Release|Any CPU
{F5E8F68F-1DB2-40A0-8071-6B6D2D2F7EC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5E8F68F-1DB2-40A0-8071-6B6D2D2F7EC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F5E8F68F-1DB2-40A0-8071-6B6D2D2F7EC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F5E8F68F-1DB2-40A0-8071-6B6D2D2F7EC5}.Release|Any CPU.Build.0 = Release|Any CPU
{FC53BA36-7FE5-4D3B-944B-CD0F34FD0320}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC53BA36-7FE5-4D3B-944B-CD0F34FD0320}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC53BA36-7FE5-4D3B-944B-CD0F34FD0320}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC53BA36-7FE5-4D3B-944B-CD0F34FD0320}.Release|Any CPU.Build.0 = Release|Any CPU
{D1117618-BB2A-4FD0-9C88-9512B9AFC76D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1117618-BB2A-4FD0-9C88-9512B9AFC76D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1117618-BB2A-4FD0-9C88-9512B9AFC76D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1117618-BB2A-4FD0-9C88-9512B9AFC76D}.Release|Any CPU.Build.0 = Release|Any CPU
{30A8E652-AD3F-42B8-AEDB-133660992475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30A8E652-AD3F-42B8-AEDB-133660992475}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30A8E652-AD3F-42B8-AEDB-133660992475}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30A8E652-AD3F-42B8-AEDB-133660992475}.Release|Any CPU.Build.0 = Release|Any CPU
{99DA5DAF-7F69-4F23-BE79-A2595ACFC849}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99DA5DAF-7F69-4F23-BE79-A2595ACFC849}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99DA5DAF-7F69-4F23-BE79-A2595ACFC849}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99DA5DAF-7F69-4F23-BE79-A2595ACFC849}.Release|Any CPU.Build.0 = Release|Any CPU
{525124A3-58D5-4301-A898-967D999CFB61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{525124A3-58D5-4301-A898-967D999CFB61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{525124A3-58D5-4301-A898-967D999CFB61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{525124A3-58D5-4301-A898-967D999CFB61}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -74,10 +81,11 @@ Global
{263050E7-B671-4A38-8A20-F933FB9AD987} = {24F9EFE8-010B-48D9-B5D2-EF194BDEAC31}
{A01CDEBF-8DB4-4792-9366-D53A91F2292D} = {9BE8804F-BCC0-48CF-9AEC-ED97414B0C78}
{188E0288-2D1F-4618-A8DC-8AAF6281A713} = {EDEC7D8F-4C6F-4DE3-8022-17A2A23AB18B}
{F5E8F68F-1DB2-40A0-8071-6B6D2D2F7EC5} = {38E0E64A-6A46-47C7-A169-24A6069D80E4}
{38E0E64A-6A46-47C7-A169-24A6069D80E4} = {EDEC7D8F-4C6F-4DE3-8022-17A2A23AB18B}
{FC53BA36-7FE5-4D3B-944B-CD0F34FD0320} = {38E0E64A-6A46-47C7-A169-24A6069D80E4}
{D1117618-BB2A-4FD0-9C88-9512B9AFC76D} = {24F9EFE8-010B-48D9-B5D2-EF194BDEAC31}
{30A8E652-AD3F-42B8-AEDB-133660992475} = {38E0E64A-6A46-47C7-A169-24A6069D80E4}
{99DA5DAF-7F69-4F23-BE79-A2595ACFC849} = {38E0E64A-6A46-47C7-A169-24A6069D80E4}
{525124A3-58D5-4301-A898-967D999CFB61} = {38E0E64A-6A46-47C7-A169-24A6069D80E4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A52A2019-EEE6-4DAB-B111-C10693C9E03B}
Expand Down
54 changes: 27 additions & 27 deletions samples/SamplePermissions/InvoicesContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SamplePermissions
{
using MadEyeMatt.AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore;
using MadEyeMatt.AspNetCore.Authorization.Permissions.Identity.Model;
using MadEyeMatt.AspNetCore.Identity.Permissions.EntityFrameworkCore;
using MadEyeMatt.AspNetCore.Identity.Permissions.Model;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -51,24 +51,24 @@ protected override void OnModelCreating(ModelBuilder builder)
options.TenantRolesTable = "TenantRoles";
});

builder.Entity<PermissionsUser>(entity =>
builder.Entity<IdentityTenantUser>(entity =>
{
// The password for every user: 123456
entity.HasData(new PermissionsUser
entity.HasData(new IdentityTenantUser
{
Id = "a0f112af-5e39-4b3f-bc50-015591861ec0",
UserName = "boss@company",
NormalizedUserName = "BOSS@COMPANY",
PasswordHash = "AQAAAAEAACcQAAAAEJ5tM19BCnMGTsQz8r8yFNvc4q9iWwkmCYHCsQYQUjlJ3XbZr1fx3tEC1QNNFxiuKA=="
});
entity.HasData(new PermissionsUser
entity.HasData(new IdentityTenantUser
{
Id = "90a4dd66-78d1-4fff-a507-7f88735f7ab6",
UserName = "manager@company",
NormalizedUserName = "MANAGER@COMPANY",
PasswordHash = "AQAAAAEAACcQAAAAEJ5tM19BCnMGTsQz8r8yFNvc4q9iWwkmCYHCsQYQUjlJ3XbZr1fx3tEC1QNNFxiuKA=="
});
entity.HasData(new PermissionsUser
entity.HasData(new IdentityTenantUser
{
Id = "04517a45-d6f5-4993-888b-04c924902b3a",
UserName = "employee@company",
Expand All @@ -77,55 +77,55 @@ protected override void OnModelCreating(ModelBuilder builder)
});
});

builder.Entity<PermissionsRole>(entity =>
builder.Entity<IdentityRole>(entity =>
{
entity.HasData(new PermissionsRole
{
entity.HasData(new IdentityRole
{
Id = "b0df7eae-a4f9-4d58-8795-ead2aaf6a483",
Name = "Boss",
NormalizedName = "BOSS"
});
entity.HasData(new PermissionsRole
{
entity.HasData(new IdentityRole
{
Id = "2c77ea15-1559-4b9b-bc20-1d64892e4297",
Name = "Manager",
NormalizedName = "MANAGER"
});
entity.HasData(new PermissionsRole
{
entity.HasData(new IdentityRole
{
Id = "c7ebaa11-c7ed-4357-b287-e0f2dd1eb3f2",
Name = "Employee",
NormalizedName = "EMPLOYEE"
});
});

builder.Entity<PermissionsPermission>(entity =>
builder.Entity<IdentityPermission>(entity =>
{
entity.HasData(new PermissionsPermission
entity.HasData(new IdentityPermission
{
Id = "5b9c4926-3dc6-447c-a092-addab890a15f",
Name = "Invoice.Read",
NormalizedName = "INVOICE.READ"
});
entity.HasData(new PermissionsPermission
entity.HasData(new IdentityPermission
{
Id = "be5b92e5-c6c6-480b-b235-d4df402a73cc",
Name = "Invoice.Write",
NormalizedName = "INVOICE.WRITE"
});
entity.HasData(new PermissionsPermission
entity.HasData(new IdentityPermission
{
Id = "e123b8c0-0646-4075-b73e-07ca9d611c8e",
Name = "Invoice.Delete",
NormalizedName = "INVOICE.DELETE"
});
entity.HasData(new PermissionsPermission
entity.HasData(new IdentityPermission
{
Id = "9dcb49c9-e732-4fb9-80a1-2c5efda61ab2",
Name = "Invoice.Send",
NormalizedName = "INVOICE.SEND"
});
entity.HasData(new PermissionsPermission
entity.HasData(new IdentityPermission
{
Id = "ef54d62d-a36b-4ab3-b868-f170c0054fac",
Name = "Invoice.Payment",
Expand Down Expand Up @@ -157,44 +157,44 @@ protected override void OnModelCreating(ModelBuilder builder)
});
});

builder.Entity<PermissionsRolePermission>(entity =>
builder.Entity<IdentityRolePermission>(entity =>
{
// Boss role permissions
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "b0df7eae-a4f9-4d58-8795-ead2aaf6a483",
PermissionId = "5b9c4926-3dc6-447c-a092-addab890a15f"
});

// Manager role permissions
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "2c77ea15-1559-4b9b-bc20-1d64892e4297",
PermissionId = "5b9c4926-3dc6-447c-a092-addab890a15f"
});
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "2c77ea15-1559-4b9b-bc20-1d64892e4297",
PermissionId = "e123b8c0-0646-4075-b73e-07ca9d611c8e"
});

// Employee role permissions
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "c7ebaa11-c7ed-4357-b287-e0f2dd1eb3f2",
PermissionId = "5b9c4926-3dc6-447c-a092-addab890a15f"
});
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "c7ebaa11-c7ed-4357-b287-e0f2dd1eb3f2",
PermissionId = "be5b92e5-c6c6-480b-b235-d4df402a73cc"
});
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "c7ebaa11-c7ed-4357-b287-e0f2dd1eb3f2",
PermissionId = "9dcb49c9-e732-4fb9-80a1-2c5efda61ab2"
});
entity.HasData(new PermissionsRolePermission
entity.HasData(new IdentityRolePermission
{
RoleId = "c7ebaa11-c7ed-4357-b287-e0f2dd1eb3f2",
PermissionId = "ef54d62d-a36b-4ab3-b868-f170c0054fac"
Expand Down
2 changes: 1 addition & 1 deletion samples/SamplePermissions/Pages/InvoiceRead.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SamplePermissions.Pages
{
using MadEyeMatt.AspNetCore.Authorization.Permissions.Abstractions;
using MadEyeMatt.AspNetCore.Authorization.Permissions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
Expand Down
2 changes: 1 addition & 1 deletion samples/SamplePermissions/Pages/Invoices.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page
@using MadEyeMatt.AspNetCore.Authorization.Permissions.Abstractions
@using MadEyeMatt.AspNetCore.Authorization.Permissions
@model InvoicesModel

@{
Expand Down
2 changes: 1 addition & 1 deletion samples/SamplePermissions/Pages/Permissions.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page
@using System.Security.Claims
@using MadEyeMatt.AspNetCore.Authorization.Permissions.Abstractions
@using MadEyeMatt.AspNetCore.Authorization.Permissions
@model PermissionsModel

@{
Expand Down
6 changes: 3 additions & 3 deletions samples/SamplePermissions/Pages/Shared/_LoginPartial.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using MadEyeMatt.AspNetCore.Authorization.Permissions.Identity.Model
@using MadEyeMatt.AspNetCore.Identity.Permissions.Model
@using Microsoft.AspNetCore.Identity
@inject SignInManager<PermissionsUser> signInManager
@inject UserManager<PermissionsUser> userManager
@inject SignInManager<IdentityTenantUser> signInManager
@inject UserManager<IdentityTenantUser> userManager

<ul class="navbar-nav">
@if(signInManager.IsSignedIn(User))
Expand Down
4 changes: 2 additions & 2 deletions samples/SamplePermissions/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MadEyeMatt.AspNetCore.Authorization.Permissions;
using MadEyeMatt.AspNetCore.Authorization.Permissions.Identity;
using MadEyeMatt.AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore;
using MadEyeMatt.AspNetCore.Identity.Permissions;
using MadEyeMatt.AspNetCore.Identity.Permissions.EntityFrameworkCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
Expand Down
5 changes: 3 additions & 2 deletions samples/SamplePermissions/SamplePermissions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore\AspNetCore.Authorization.Permissions.Identity.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\AspNetCore.Authorization.Permissions.Identity\AspNetCore.Authorization.Permissions.Identity.csproj" />
<ProjectReference Include="..\..\src\AspNetCore.Authorization.Permissions.Abstractions\AspNetCore.Authorization.Permissions.Abstractions.csproj" />
<ProjectReference Include="..\..\src\AspNetCore.Authorization.Permissions\AspNetCore.Authorization.Permissions.csproj" />
<ProjectReference Include="..\..\src\AspNetCore.Identity.Permissions.EntityFrameworkCore\AspNetCore.Identity.Permissions.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\AspNetCore.Identity.Permissions\AspNetCore.Identity.Permissions.csproj" />
</ItemGroup>

</Project>
Binary file removed samples/SamplePermissions/permissions.db
Binary file not shown.
24 changes: 12 additions & 12 deletions samples/SampleTenant/InvoiceConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace SampleTenant
{
using System;
using MadEyeMatt.AspNetCore.Authorization.Permissions.Abstractions;
using MadEyeMatt.AspNetCore.Authorization.Permissions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.ValueGeneration;
Expand All @@ -25,30 +25,30 @@ public void Configure(EntityTypeBuilder<Invoice> builder)
builder.Property(x => x.Id).HasValueGenerator<SequentialGuidValueGenerator>();

// Add a tenant query filter.
builder.HasIndex(x => x.TenantId).HasDatabaseName("InvoiceTenantIdIndex");
builder.HasQueryFilter(x => x.TenantId == this.tenantProvider.TenantId);
builder.HasIndex(x => x.TenantID).HasDatabaseName("InvoiceTenantIdIndex");
builder.HasQueryFilter(x => x.TenantID == this.tenantProvider.TenantID);

// Startup invoices
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 99.95m,
Note = "This is a Startup invoice.",
TenantId = "7d706acd-f5fd-4979-9e3f-c77a0bd596b2"
TenantID = "7d706acd-f5fd-4979-9e3f-c77a0bd596b2"
});
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 99.95m,
Note = "This is a Startup invoice.",
TenantId = "7d706acd-f5fd-4979-9e3f-c77a0bd596b2"
TenantID = "7d706acd-f5fd-4979-9e3f-c77a0bd596b2"
});
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 99.95m,
Note = "This is a Startup invoice.",
TenantId = "7d706acd-f5fd-4979-9e3f-c77a0bd596b2"
TenantID = "7d706acd-f5fd-4979-9e3f-c77a0bd596b2"
});

// Company invoices
Expand All @@ -57,21 +57,21 @@ public void Configure(EntityTypeBuilder<Invoice> builder)
Id = Guid.NewGuid(),
Total = 199.95m,
Note = "This is a Company invoice.",
TenantId = "ee5128d3-4cad-4bcc-aa64-f6abbb30da46"
TenantID = "ee5128d3-4cad-4bcc-aa64-f6abbb30da46"
});
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 199.95m,
Note = "This is a Company invoice.",
TenantId = "ee5128d3-4cad-4bcc-aa64-f6abbb30da46"
TenantID = "ee5128d3-4cad-4bcc-aa64-f6abbb30da46"
});
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 199.95m,
Note = "This is a Company invoice.",
TenantId = "ee5128d3-4cad-4bcc-aa64-f6abbb30da46"
TenantID = "ee5128d3-4cad-4bcc-aa64-f6abbb30da46"
});

// Corporate invoices
Expand All @@ -80,21 +80,21 @@ public void Configure(EntityTypeBuilder<Invoice> builder)
Id = Guid.NewGuid(),
Total = 399.95m,
Note = "This is a Corporate invoice.",
TenantId = "49a049d2-23ad-41df-8806-240aebaa2f17"
TenantID = "49a049d2-23ad-41df-8806-240aebaa2f17"
});
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 399.95m,
Note = "This is a Corporate invoice.",
TenantId = "49a049d2-23ad-41df-8806-240aebaa2f17"
TenantID = "49a049d2-23ad-41df-8806-240aebaa2f17"
});
builder.HasData(new Invoice
{
Id = Guid.NewGuid(),
Total = 399.95m,
Note = "This is a Corporate invoice.",
TenantId = "49a049d2-23ad-41df-8806-240aebaa2f17"
TenantID = "49a049d2-23ad-41df-8806-240aebaa2f17"
});
}
}
Expand Down
Loading

0 comments on commit 3059784

Please sign in to comment.