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?}"
|
@page "/server/{id:int?}"
|
||||||
|
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
|
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject IJSRuntime JSRuntime
|
@inject IJSRuntime JSRuntime
|
||||||
@inject IServersEFCoreRepository ServersEFCoreRepository
|
@inject IServersEFCoreRepository ServersEFCoreRepository
|
||||||
|
|
||||||
|
@attribute [Authorize(Policy = "Administrator")]
|
||||||
|
|
||||||
<NavigationLock
|
<NavigationLock
|
||||||
OnBeforeInternalNavigation="OnBeforeInternalNavigation"
|
OnBeforeInternalNavigation="OnBeforeInternalNavigation"
|
||||||
ConfirmExternalNavigation="true">
|
ConfirmExternalNavigation="true">
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
@page "/cityname"
|
@page "/cityname"
|
||||||
|
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using ServerManagement.StateStore
|
@using ServerManagement.StateStore
|
||||||
|
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject ContainerStorage containerStorage
|
@inject ContainerStorage containerStorage
|
||||||
|
|
||||||
|
@attribute [Authorize]
|
||||||
|
|
||||||
<h3>City Name</h3>
|
<h3>City Name</h3>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
@page "/servername"
|
@page "/servername"
|
||||||
|
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using ServerManagement.StateStore
|
@using ServerManagement.StateStore
|
||||||
|
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject ContainerStorage containerStorage
|
@inject ContainerStorage containerStorage
|
||||||
|
|
||||||
|
@attribute [Authorize]
|
||||||
|
|
||||||
<h3>Server Name</h3>
|
<h3>Server Name</h3>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
@page "/serverstatus"
|
@page "/serverstatus"
|
||||||
|
|
||||||
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using ServerManagement.StateStore
|
@using ServerManagement.StateStore
|
||||||
|
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject ContainerStorage containerStorage
|
@inject ContainerStorage containerStorage
|
||||||
@inject IServersEFCoreRepository ServersEFCoreRepository
|
@inject IServersEFCoreRepository ServersEFCoreRepository
|
||||||
|
|
||||||
|
@attribute [Authorize]
|
||||||
|
|
||||||
<h3>Server Status</h3>
|
<h3>Server Status</h3>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,12 @@ builder.Services.AddAuthentication(options =>
|
|||||||
})
|
})
|
||||||
.AddIdentityCookies();
|
.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.");
|
var connectionString = builder.Configuration.GetConnectionString("ServerManagement") ?? throw new InvalidOperationException("Connection string 'ServerManagement' not found.");
|
||||||
builder.Services.AddDbContext<IdentityContext>(options =>
|
builder.Services.AddDbContext<IdentityContext>(options =>
|
||||||
options.UseSqlite(connectionString));
|
options.UseSqlite(connectionString));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user