diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Security/Auth/AuthDisableLoginOptions.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Security/Auth/AuthDisableLoginOptions.cs new file mode 100644 index 00000000..bd330101 --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Security/Auth/AuthDisableLoginOptions.cs @@ -0,0 +1,18 @@ +namespace ZB.MOM.WW.OtOpcUa.Security.Auth; + +/// +/// Dev/test flag: when is true the AdminUI bypasses the login +/// form entirely and auto-authenticates every request as with all roles. +/// Default OFF. Never enable in production. +/// +public sealed class AuthDisableLoginOptions +{ + /// Configuration section name (Security:Auth). + public const string SectionName = "Security:Auth"; + + /// When true, disable login and auto-authenticate every request. Default false. + public bool DisableLogin { get; set; } + + /// The username the auto-login principal is minted with. Default "multi-role-test". + public string User { get; set; } = "multi-role-test"; +} diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Security/Auth/DevAuthRoles.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Security/Auth/DevAuthRoles.cs new file mode 100644 index 00000000..0683026f --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Security/Auth/DevAuthRoles.cs @@ -0,0 +1,18 @@ +using ZB.MOM.WW.OtOpcUa.Configuration.Enums; + +namespace ZB.MOM.WW.OtOpcUa.Security.Auth; + +/// +/// The full canonical role set granted to the auto-login dev principal: every +/// plus the appsettings-only control-plane role "Operator" +/// (required by the DriverOperator policy). Centralised so adding an AdminRole +/// automatically widens the grant. +/// +public static class DevAuthRoles +{ + /// Operator role string — not an enum member; used by the DriverOperator policy. + public const string Operator = "Operator"; + + /// All roles granted to the auto-login principal. + public static readonly string[] All = [.. Enum.GetNames(), Operator]; +} diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests/DevAuthRolesTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests/DevAuthRolesTests.cs new file mode 100644 index 00000000..a0975f2b --- /dev/null +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests/DevAuthRolesTests.cs @@ -0,0 +1,19 @@ +using Shouldly; +using Xunit; +using ZB.MOM.WW.OtOpcUa.Configuration.Enums; +using ZB.MOM.WW.OtOpcUa.Security.Auth; + +namespace ZB.MOM.WW.OtOpcUa.Security.Tests; + +public class DevAuthRolesTests +{ + [Fact] + public void All_covers_every_AdminRole_plus_Operator() + { + foreach (var name in Enum.GetNames()) + DevAuthRoles.All.ShouldContain(name); + DevAuthRoles.All.ShouldContain("Operator"); + DevAuthRoles.All.Length.ShouldBe(Enum.GetNames().Length + 1); + DevAuthRoles.All.Distinct().Count().ShouldBe(DevAuthRoles.All.Length); + } +}