Skip to content

Commit

Permalink
Permissions with Policy and Claims
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-liu-toronto committed Jun 11, 2024
1 parent 4b92954 commit e9465e2
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/produce"

@attribute [Authorize]
@attribute [Authorize(Policy = "Productions")]

@rendermode InteractiveServer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@using static IMS.WebApp.Components.Controls.Common.AutoCompleteComponent

@attribute [Authorize]
@attribute [Authorize(Policy = "Purchasers")]

@rendermode InteractiveServer

Expand Down
2 changes: 1 addition & 1 deletion IMS.WebApp/Components/Pages/Activities/SellProduct.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@page "/sell"

@attribute [Authorize]
@attribute [Authorize(Policy = "Sales")]

@rendermode InteractiveServer

Expand Down
2 changes: 1 addition & 1 deletion IMS.WebApp/Components/Pages/Inventories/AddInventory.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/addinventory"

@attribute [Authorize]
@attribute [Authorize(Policy = "Inventory")]

@inject IAddInventoryUseCase AddInventoryUseCase
@inject NavigationManager NavigationManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/editinventory/{invId:int}"

@attribute [Authorize]
@attribute [Authorize(Policy = "Inventory")]

@inject NavigationManager NavigationManager
@inject IViewInventoryByIdUseCase ViewInventoryByIdUseCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/inventories"

@attribute [Authorize]
@attribute [Authorize(Policy = "Inventory")]

<h3>Inventory List</h3>
<br/>
Expand Down
2 changes: 1 addition & 1 deletion IMS.WebApp/Components/Pages/Products/AddProduct.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/addproduct"

@attribute [Authorize]
@attribute [Authorize(Policy = "Inventory")]

@rendermode InteractiveServer

Expand Down
2 changes: 1 addition & 1 deletion IMS.WebApp/Components/Pages/Products/EditProduct.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/editproduct/{id:int}"

@attribute [Authorize]
@attribute [Authorize(Policy = "Inventory")]

@rendermode InteractiveServer

Expand Down
2 changes: 1 addition & 1 deletion IMS.WebApp/Components/Pages/Products/ProductList.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/products"

@attribute [Authorize]
@attribute [Authorize(Policy = "Inventory")]

<h3>Product List</h3>
<br/>
Expand Down
9 changes: 8 additions & 1 deletion IMS.WebApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
builder.Services.AddScoped<IdentityRedirectManager>();
builder.Services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();

builder.Services.AddAuthorization();
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("Admin", policy => policy.RequireClaim("Department", "Administration"));
options.AddPolicy("Inventory", policy => policy.RequireClaim("Department", "InventoryManagement"));
options.AddPolicy("Sales", policy => policy.RequireClaim("Department", "Sales"));
options.AddPolicy("Purchasers", policy => policy.RequireClaim("Department", "Purchasing"));
options.AddPolicy("Productions", policy => policy.RequireClaim("Department", "ProducitonManagement"));
});
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = IdentityConstants.ApplicationScheme;
Expand Down

0 comments on commit e9465e2

Please sign in to comment.