Add policy authorization based on claim for admin role.
Note that this redirects to the login page, it should actually display an Access Denied message.
This commit is contained in:
parent
068407cfcb
commit
b65d998b01
@ -1,9 +1,13 @@
|
||||
@page "/server/{id:int?}"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IServersEFCoreRepository ServersEFCoreRepository
|
||||
|
||||
@attribute [Authorize(Policy = "Administrator")]
|
||||
|
||||
<NavigationLock
|
||||
OnBeforeInternalNavigation="OnBeforeInternalNavigation"
|
||||
ConfirmExternalNavigation="true">
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
@page "/cityname"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using ServerManagement.StateStore
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject ContainerStorage containerStorage
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<h3>City Name</h3>
|
||||
<br/>
|
||||
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
@page "/servername"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using ServerManagement.StateStore
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject ContainerStorage containerStorage
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<h3>Server Name</h3>
|
||||
<br/>
|
||||
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
@page "/serverstatus"
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using ServerManagement.StateStore
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject ContainerStorage containerStorage
|
||||
@inject IServersEFCoreRepository ServersEFCoreRepository
|
||||
|
||||
@attribute [Authorize]
|
||||
|
||||
<h3>Server Status</h3>
|
||||
<br/>
|
||||
|
||||
|
||||
@ -55,6 +55,12 @@ builder.Services.AddAuthentication(options =>
|
||||
})
|
||||
.AddIdentityCookies();
|
||||
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("Administrator", policy => policy.RequireClaim("Role", "Admin"));
|
||||
}
|
||||
);
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("ServerManagement") ?? throw new InvalidOperationException("Connection string 'ServerManagement' not found.");
|
||||
builder.Services.AddDbContext<IdentityContext>(options =>
|
||||
options.UseSqlite(connectionString));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user