Unify gateway styling and preserve identity through recovery
This commit is contained in:
@@ -71,7 +71,7 @@ using ZB.MOM.WW.MxGateway.Server.Security.Authorization;
|
||||
internal sealed class ManagingApiKeyService : IDashboardApiKeyManagementService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public bool CanManage(ClaimsPrincipal user) => true;
|
||||
public bool CanManage(ClaimsPrincipal user) => user.IsInRole(DashboardRoles.Admin);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<DashboardApiKeyManagementResult> CreateAsync(
|
||||
@@ -102,15 +102,16 @@ using ZB.MOM.WW.MxGateway.Server.Security.Authorization;
|
||||
Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised"));
|
||||
}
|
||||
|
||||
internal sealed class StubAuthenticationStateProvider : AuthenticationStateProvider
|
||||
internal sealed class StubAuthenticationStateProvider(Microsoft.AspNetCore.Components.NavigationManager nav) : AuthenticationStateProvider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync() =>
|
||||
Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(
|
||||
[new Claim(ClaimTypes.Name, "admin-user"), new Claim(ClaimTypes.Role, DashboardRoles.Admin)],
|
||||
authenticationType: "test",
|
||||
nameType: ClaimTypes.Name,
|
||||
roleType: ClaimTypes.Role))));
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(new Uri(nav.Uri).Query);
|
||||
string role = query.TryGetValue("principal", out var value) ? value.ToString() : "admin";
|
||||
var identity = role == "anonymous" ? new ClaimsIdentity() : new ClaimsIdentity(
|
||||
[new Claim(ClaimTypes.Name, "fixture-user"), new Claim(ClaimTypes.Role, role == "viewer" ? DashboardRoles.Viewer : DashboardRoles.Admin)], "synthetic");
|
||||
return Task.FromResult(new AuthenticationState(new ClaimsPrincipal(identity)));
|
||||
}
|
||||
}
|
||||
// In-memory Galaxy projection and read-only fake values for the actual BrowsePage.
|
||||
internal sealed class FixtureGalaxyCache : ZB.MOM.WW.GalaxyRepository.IGalaxyHierarchyCache
|
||||
@@ -124,7 +125,7 @@ internal sealed class FixtureGalaxyCache : ZB.MOM.WW.GalaxyRepository.IGalaxyHie
|
||||
pump.Attributes.Add(new ZB.MOM.WW.GalaxyRepository.Grpc.GalaxyAttribute { AttributeName = new string('x', 200), FullTagReference = "Pump01." + new string('x', 200), DataTypeName = "Float" });
|
||||
var sibling = new ZB.MOM.WW.GalaxyRepository.Grpc.GalaxyObject { GobjectId = 3, ParentGobjectId = 1, TagName = "Sibling01", BrowseName = "Sibling01" };
|
||||
sibling.Attributes.Add(new ZB.MOM.WW.GalaxyRepository.Grpc.GalaxyAttribute { AttributeName = "PV", FullTagReference = "Sibling01.PV", DataTypeName = "Float" });
|
||||
ZB.MOM.WW.GalaxyRepository.Grpc.GalaxyObject[] rows = [plant, pump, sibling];
|
||||
ZB.MOM.WW.GalaxyRepository.Grpc.GalaxyObject[] rows = [plant, pump, sibling, new() { GobjectId=4, ParentGobjectId=2, TagName="PumpChild", BrowseName="PumpChild" }];
|
||||
Current = ZB.MOM.WW.GalaxyRepository.GalaxyHierarchyCacheEntry.Empty with {
|
||||
Status = ZB.MOM.WW.GalaxyRepository.GalaxyCacheStatus.Healthy, Sequence = 1,
|
||||
Objects = rows, Index = ZB.MOM.WW.GalaxyRepository.GalaxyHierarchyIndex.Build(rows), ObjectCount = rows.Length, AttributeCount = 3,
|
||||
@@ -141,3 +142,18 @@ internal sealed class FixtureLiveData : IDashboardLiveDataService
|
||||
public Task<DashboardAlarmQueryResult> QueryAlarmsAsync(CancellationToken cancellationToken) =>
|
||||
Task.FromResult(new DashboardAlarmQueryResult([], null, null));
|
||||
}
|
||||
|
||||
internal sealed class FaultableBrowseService(ZB.MOM.WW.GalaxyRepository.IGalaxyHierarchyCache cache) : IDashboardBrowseService
|
||||
{
|
||||
private readonly DashboardBrowseService _real = new(cache);
|
||||
public bool FailNext { get; set; }
|
||||
public int Attempts { get; private set; }
|
||||
public ulong CurrentCacheSequence => _real.CurrentCacheSequence;
|
||||
public BrowseLevelResult GetRoots(BrowseFilterArgs filter) => _real.GetRoots(filter);
|
||||
public BrowseLevelResult GetChildren(int id, BrowseFilterArgs filter)
|
||||
{
|
||||
Attempts++;
|
||||
if (FailNext) { FailNext = false; throw new InvalidOperationException("Synthetic hierarchy outage " + new string('x', 600) + " <script>fixture</script>"); }
|
||||
return _real.GetChildren(id, filter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user