This PR implements the **OPC UA Device Integration (DI, OPC 10000-100)**
companion-spec library trio (`Opc.Ua.Di` / `Opc.Ua.Di.Server` /
`Opc.Ua.Di.Client`) plus a worked example
(`Applications/MinimalPumpServer`) demonstrating the OPC 40223 Pumps
companion specification end-to-end with full simulation. It also closes
11 fluent-API gaps in `Opc.Ua.Server.Fluent`, three source-generator
bugs, integrates the DI layer into the unified `services.AddOpcUa()`
Microsoft.Extensions DI hosting pattern, and adds 250+ new tests.
**Worked example — `Applications/MinimalPumpServer/`**
- AOT-compatible console host using `Host.CreateApplicationBuilder` +
`AddOpcUa()`.
- `PumpNodeManager` inherits from `DiNodeManager`; multi-namespace (DI +
Machinery + Pumps) via runtime NodeSet2 loading and
`ModelLoaderBuilder`.
- Demonstrates declarative second-pump creation via
`.ConfigureDevicesFor<PumpNodeManager>(...)` and software-package
seeding from the same configurator.
- Full simulation: pressure, temperatures, power, flow, efficiency,
level, cavitation/overheat fault injection, alarm setup, NAMUR-style
supervision.
**Documentation**
- `Docs/Opc.Ua.Di/` — README, DeviceBuilder, Hosting, LockService,
SoftwareUpdate, ClientHelpers (6 new developer guides).
- `Docs/Opc.Ua.Di/ComplianceMatrix.md` — every DI declaration mapped to
In-v1 / Generated / Deferred / Excluded.
- `Docs/CompanionSpecLibraries.md` — packaging guide for new
companion-spec libraries.
- `Docs/FluentApiGaps.md` — historical record of G1–G11.
- `Docs/SourceGeneratedNodeManagers.md` updated for richer node
managers.
- `Docs/plans/StateMachineBuilder.md` — deferred state-machine builder
design.
**User Management Improvements:**
* The `UserManagement` class now loads existing users from the user
database during initialization, ensuring that the in-memory user list
reflects the database state through the abstraction boundary.
* The `IUserDatabase` interface now exposes `GetUsers()`, returning
`UserManagementDataType` records instead of only user names.
* `UserManagement.LoadUsersFromDatabase()` now consumes
`IUserDatabase.GetUsers()` so custom user database implementations can
provide persisted user metadata such as `UserConfiguration` and
`Description`.
* `LinqUserDatabase` implements `GetUsers()` and returns user records
with the stored user name and default user-management metadata.
`JsonUserDatabase` inherits this behavior through `LinqUserDatabase`.
**Address Space Management:**
* The server now properly removes the UserManagement node from the
address space when user management is not enabled, preventing stale or
orphaned nodes.
**Test Coverage Enhancements:**
* Added tests to verify that the UserManagement node is removed when
user management is not present.
* Added tests to confirm that `LinqUserDatabase.GetUsers()` returns the
correct users.
* Added tests to confirm that `UserManagement` starts with all users
from the database, including custom `IUserDatabase` implementations that
return full `UserManagementDataType` metadata.
These changes keep user discovery on the `IUserDatabase` abstraction,
remove the concrete-type dependency from startup, and allow existing
users to be loaded with their associated management metadata.
Drive the solution to zero warnings / zero errors with analyzers on,
promote the consistently-fixed rules to error, and lock in coverage
on the only line of new logic.
* role management compliant with OPC UA Part 18
Server-side:
- New IRoleManager / RoleManager with spec-correct status codes
(Bad_AlreadyExists, Bad_NodeIdUnknown, Bad_RequestNotAllowed,
Bad_NotFound) for every mutator per Part 18 4.2 / 4.4.
- Pre-populate default identities for the three reserved well-known
roles per Part 18 4.3 (Anonymous, AuthenticatedUser,
TrustedApplication).
- Reject mutations on reserved roles with Bad_RequestNotAllowed.
- Validate IdentityMappingRuleType per Part 18 4.4.3 (empty criteria
for Anonymous/AuthenticatedUser/TrustedApplication; upper-case hex
for Thumbprint; Name=Value grammar for X509Subject).
- Honour Part 18 4.4.2 default-field-as-wildcard EndpointType
comparisons; tighten TrustedApplication/Application rules to
require trusted certificate + signed channel.
- Introduce CustomConfiguration flag per Part 18 4.4.1.
- Add IRoleManager.RoleConfigurationChanged event raised after every
successful mutation per Part 18 4.4.1.
- Make RoleEntry an immutable snapshot.
Address-space binding (typed proxies):
- RoleStateBinding switched from stringly-typed OnCallMethod2 plumbing
to the source-generated typed proxies (RoleSetState, RoleState,
AddRoleMethodState, AddIdentityMethodState, ...).
- DiagnosticsNodeManager.AddBehaviourToPredefinedNodeAsync upgrades
passive BaseObjectState nodes of RoleSetType / RoleType to the
typed RoleSetState / RoleState proxies at predefined-node load time.
- New RoleAuthorizationGate.CheckAdmin centralizes SecurityAdmin role
plus SignAndEncrypt enforcement per Part 18 4.2 / 4.4 / 5.2.
- Bound writable ApplicationsExclude / EndpointsExclude /
CustomConfiguration with the same auth gate.
- Raise RoleMappingRuleChangedAuditEventType from every successful
mutator (Part 18 4.5) via the existing AuditEvents helper.
Client library:
- New Opc.Ua.Client.Roles.RoleManagementClient + IRoleManagementClient
+ RoleInfo + SessionRoleExtensions.OpenRoleManagementClient.
- Covers list / read / add / remove role, identity, application,
endpoint operations plus Set*Exclude via Write Service.
Tests:
- New RoleManagerTests.cs - 37 NUnit tests for pre-populated roles,
reserved-role immutability, spec-correct status codes, criteria
validation, ResolveGrantedRoles, exclude semantics,
CustomConfiguration, AddRole well-known NodeId reuse, and
RoleConfigurationChanged event.
Documentation:
- Rewrite Docs/RoleBasedUserManagement.md as a Part 18 compliance
reference (status-code matrix, client examples, known limitations).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add Part 18 5 UserManagement implementation
Server-side:
- New IUserManagement interface (Opc.Ua.Server.UserManagement) modelling
Part 18 5.2.1 surface: PasswordLength, PasswordOptions, PasswordRestrictions,
SnapshotUsers, AddUser, ModifyUser, RemoveUser, ChangePassword,
MustChangePassword, IsUserActive, UserDeactivated event.
- Default UserManagement implementation wraps the existing IUserDatabase
and stores per-user UserConfigurationMask + description in memory.
Validates passwords against PasswordLength + character-class flags
from PasswordOptions; honours Part 18 5.2 result codes
(Bad_AlreadyExists, Bad_NotFound, Bad_OutOfRange, Bad_NotSupported,
Bad_ConfigurationError, Bad_InvalidSelfReference,
Bad_IdentityTokenInvalid).
- ChangePassword clears the MustChangePassword bit on success.
- New UserManagementBinding wires the typed source-generated proxies
(UserManagementState, AddUserMethodState, ModifyUserMethodState,
RemoveUserMethodState, ChangePasswordMethodState) - typed OnCallAsync
delegates everywhere; admin gate via RoleAuthorizationGate.CheckAdmin;
ChangePassword gated via RoleAuthorizationGate.CheckSelfUserName;
closes active sessions for deactivated users via ISessionManager.
- ConfigurationNodeManager.AddBehaviourToPredefinedNodeAsync upgrades
the passive UserManagement object to the typed UserManagementState
proxy at predefined-node load time; CreateServerConfiguration invokes
UserManagementBinding.Bind when an IUserManagement was injected.
- IServerInternal gains UserManagement getter + SetUserManagement
injector.
Tests:
- New Tests/Opc.Ua.Server.Tests/UserManagementTests.cs - 18 NUnit tests
covering AddUser happy path, duplicate / password-length / config-flag
validation, RemoveUser non-existent / self-reference / NoDelete,
ModifyUser self-disable / disable-other UserDeactivated event,
ChangePassword happy path / same-as-old / wrong-old /
MustChangePassword bit clearing / NoChangeByUser rejection,
IsUserActive on disabled vs active users.
Documentation:
- Update Docs/RoleBasedUserManagement.md with a User Management section
including the spec result-code matrix, example wiring code, and
reduce known limitations - UserManagement is no longer a limitation.