mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-18 22:55:08 +08:00
0000513cde
# Description Introduces a pluggable user-identity provider model covering all OPC UA Part 6 §6.5 mechanisms (Anonymous, UserName, X509, IssuedToken/JWT) on both client and server, with full `Microsoft.Extensions.DependencyInjection` integration, plus the Part 12 §9 `AuthorizationService` two-phase token-request flow **including refresh-token rotation**, the Part 12 §8 KeyCredential Push model, and a clean provider model for OPC 10000-12 §7.2 `ApplicationSelfAdmin`. The work is split across phase-by-phase commits so it can be reviewed independently; nothing here changes wire-level behaviour or forces existing applications to migrate. ### Documentation All under `Docs/`: - `IdentityProviders.md` — full developer guide: three-layer model, recipes, configuration reference, "what gets auto-wired" matrix, JWS algorithm table, identity-augmenters section, **"Implementing your own provider"** how-to subsections for Entra / OIDC / Windows / AspNetCore (sibling files merged in per review feedback). - `DependencyInjection.md` — `Identity` sections with `appsettings.json` examples, identity-extension matrix, `WithAuthorizationService` + `WithKeyCredentialPush` + `AddIdentityAugmenter` extensions documented. - `RoleBasedUserManagement.md` — claim-criteria callout describing `IIdentityClaims` probe surface. - `AuthorizationService.md` — Architecture diagram + `IAccessTokenProvider` conceptual narrative restored from master; modern `StartRequestToken` / `FinishRequestToken` flow leads; refresh-token recipe added. - `KeyCredentialService.md` — Push model + Pull vs Push vs Bridge decision matrix + Hybrid (Push + Pull) section; explicit experimental warning for the bridge. - `GDS.md` — KeyCredential Push, `StartRequestToken`, `GdsApplicationSelfAdminProvider`, **shipped Refresh-token support with rotation policy and audit semantics** all documented. - `MigrationGuide.md` — User Identity Providers section listing `[Obsolete]` markers + mechanical recipes; SelfAdmin migration via `IIdentityAugmenter`; `EnableRefreshTokens` default note. - `README.md` index entries. ## Checklist - [x] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [x] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [x] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. - [x] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [x] I have addressed **all** PR feedback received.
407 lines
17 KiB
C#
407 lines
17 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Opc.Ua.Identity;
|
|
|
|
namespace Opc.Ua.Server
|
|
{
|
|
/// <summary>
|
|
/// The interface that a server exposes to objects that it contains.
|
|
/// </summary>
|
|
public interface IServerInternal : IAuditEventServer, IDisposable
|
|
{
|
|
/// <summary>
|
|
/// The endpoint addresses used by the server.
|
|
/// </summary>
|
|
/// <value>The endpoint addresses.</value>
|
|
IEnumerable<Uri> EndpointAddresses { get; }
|
|
|
|
/// <summary>
|
|
/// The context to use when serializing/deserializing extension objects.
|
|
/// </summary>
|
|
/// <value>The message context.</value>
|
|
IServiceMessageContext MessageContext { get; }
|
|
|
|
/// <summary>
|
|
/// The default system context for the server.
|
|
/// </summary>
|
|
/// <value>The default system context.</value>
|
|
ServerSystemContext DefaultSystemContext { get; }
|
|
|
|
/// <summary>
|
|
/// The table of namespace uris known to the server.
|
|
/// </summary>
|
|
/// <value>The namespace URIs.</value>
|
|
NamespaceTable NamespaceUris { get; }
|
|
|
|
/// <summary>
|
|
/// The table of remote server uris known to the server.
|
|
/// </summary>
|
|
/// <value>The server URIs.</value>
|
|
StringTable ServerUris { get; }
|
|
|
|
/// <summary>
|
|
/// The factory used to create encodeable objects that the server understands.
|
|
/// </summary>
|
|
/// <value>The factory.</value>
|
|
IEncodeableFactory Factory { get; }
|
|
|
|
/// <summary>
|
|
/// The datatypes, object types and variable types known to the server.
|
|
/// </summary>
|
|
/// <value>The type tree.</value>
|
|
/// <remarks>
|
|
/// The type tree table is a global object that all components of a server have access to.
|
|
/// Node managers must populate this table with all types that they define.
|
|
/// This object is thread safe.
|
|
/// </remarks>
|
|
TypeTable TypeTree { get; }
|
|
|
|
/// <summary>
|
|
/// The factory which helps creating main
|
|
/// node managers used by the server.
|
|
/// </summary>
|
|
IMainNodeManagerFactory MainNodeManagerFactory { get; }
|
|
|
|
/// <summary>
|
|
/// The master node manager for the server.
|
|
/// </summary>
|
|
/// <value>The node manager.</value>
|
|
IMasterNodeManager NodeManager { get; }
|
|
|
|
/// <summary>
|
|
/// The internal node manager for the servers.
|
|
/// </summary>
|
|
/// <value>The core node manager.</value>
|
|
ICoreNodeManager CoreNodeManager { get; }
|
|
|
|
/// <summary>
|
|
/// Returns the node manager that managers the server diagnostics.
|
|
/// </summary>
|
|
/// <value>The diagnostics node manager.</value>
|
|
IDiagnosticsNodeManager DiagnosticsNodeManager { get; }
|
|
|
|
/// <summary>
|
|
/// Returns the node manager that managers the server configuration.
|
|
/// </summary>
|
|
/// <value>The configuration node manager.</value>
|
|
IConfigurationNodeManager ConfigurationNodeManager { get; }
|
|
|
|
/// <summary>
|
|
/// The manager for events that all components use to queue events that occur.
|
|
/// </summary>
|
|
/// <value>The event manager.</value>
|
|
EventManager EventManager { get; }
|
|
|
|
/// <summary>
|
|
/// A manager for localized resources that components can use to localize text.
|
|
/// </summary>
|
|
/// <value>The resource manager.</value>
|
|
ResourceManager ResourceManager { get; }
|
|
|
|
/// <summary>
|
|
/// A manager for outstanding requests that allows components to receive notifications if the timeout or are cancelled.
|
|
/// </summary>
|
|
/// <value>The request manager.</value>
|
|
RequestManager RequestManager { get; }
|
|
|
|
/// <summary>
|
|
/// A manager for aggregate calculators supported by the server.
|
|
/// </summary>
|
|
/// <value>The aggregate manager.</value>
|
|
AggregateManager AggregateManager { get; }
|
|
|
|
/// <summary>
|
|
/// A manager for modelling rules supported by the server.
|
|
/// </summary>
|
|
/// <value>The modelling rules manager.</value>
|
|
ModellingRulesManager ModellingRulesManager { get; }
|
|
|
|
/// <summary>
|
|
/// The manager for active sessions.
|
|
/// </summary>
|
|
/// <value>The session manager.</value>
|
|
ISessionManager SessionManager { get; }
|
|
|
|
/// <summary>
|
|
/// The manager for role identity / application / endpoint mapping rules
|
|
/// per OPC UA Part 18 §6.4. <c>null</c> only on stripped-down server hosts
|
|
/// that don't expose Server.ServerCapabilities.RoleSet. Integrators may
|
|
/// override the default in-memory implementation by calling
|
|
/// <see cref="SetRoleManager"/> before the address space is bound.
|
|
/// </summary>
|
|
IRoleManager RoleManager { get; }
|
|
|
|
/// <summary>
|
|
/// The registry that validates user identity tokens before falling back
|
|
/// to the legacy <c>SessionManager.ImpersonateUser</c> event. Integrators
|
|
/// may replace the default empty registry by calling
|
|
/// <see cref="SetIdentityRegistry"/> before sessions are activated.
|
|
/// </summary>
|
|
IServerIdentityRegistry IdentityRegistry { get; }
|
|
|
|
/// <summary>
|
|
/// The manager for the OPC UA Part 18 §5 user-management model.
|
|
/// <c>null</c> when the server doesn't expose
|
|
/// <c>ServerConfiguration.UserManagement</c>. Integrators inject a
|
|
/// concrete instance by calling <see cref="SetUserManagement"/>.
|
|
/// </summary>
|
|
UserManagement.IUserManagement? UserManagement { get; }
|
|
|
|
/// <summary>
|
|
/// The manager for active subscriptions.
|
|
/// </summary>
|
|
ISubscriptionManager SubscriptionManager { get; }
|
|
|
|
/// <summary>
|
|
/// The factory for (durable) monitored item queues
|
|
/// </summary>
|
|
IMonitoredItemQueueFactory MonitoredItemQueueFactory { get; }
|
|
|
|
/// <summary>
|
|
/// The store to persist and retrieve subscriptions
|
|
/// </summary>
|
|
ISubscriptionStore SubscriptionStore { get; }
|
|
|
|
/// <summary>
|
|
/// The server's telemetry context
|
|
/// </summary>
|
|
ITelemetryContext Telemetry { get; }
|
|
|
|
/// <summary>
|
|
/// Whether the server is currently running.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if this instance is running; otherwise, <c>false</c>.
|
|
/// </value>
|
|
/// <remarks>
|
|
/// This flag is set to false when the server shuts down. Threads running should check this flag whenever
|
|
/// they return from a blocking operation. If it is false the thread should clean up and terminate.
|
|
/// </remarks>
|
|
bool IsRunning { get; }
|
|
|
|
/// <summary>
|
|
/// Returns the status object for the server.
|
|
/// </summary>
|
|
/// <value>The status.</value>
|
|
[Obsolete("No longer thread safe. To read the value use CurrentState, to write use UpdateServerStatus.")]
|
|
ServerStatusValue Status { get; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the current state of the server.
|
|
/// </summary>
|
|
/// <value>The state of the current.</value>
|
|
ServerState CurrentState { get; set; }
|
|
|
|
/// <summary>
|
|
/// Returns the Server object node
|
|
/// </summary>
|
|
/// <value>The Server object node.</value>
|
|
ServerObjectState ServerObject { get; }
|
|
|
|
/// <summary>
|
|
/// Used to synchronize access to the server diagnostics.
|
|
/// </summary>
|
|
/// <value>The diagnostics lock.</value>
|
|
object DiagnosticsLock { get; }
|
|
|
|
/// <summary>
|
|
/// Used to synchronize write access to the server diagnostics.
|
|
/// </summary>
|
|
/// <value>The diagnostics lock.</value>
|
|
object DiagnosticsWriteLock { get; }
|
|
|
|
/// <summary>
|
|
/// Returns the diagnostics structure for the server.
|
|
/// </summary>
|
|
/// <value>The server diagnostics.</value>
|
|
ServerDiagnosticsSummaryDataType ServerDiagnostics { get; }
|
|
|
|
/// <summary>
|
|
/// Whether the server is collecting diagnostics.
|
|
/// </summary>
|
|
/// <value><c>true</c> if diagnostics is enabled; otherwise, <c>false</c>.</value>
|
|
bool DiagnosticsEnabled { get; }
|
|
|
|
/// <summary>
|
|
/// Closes the specified session.
|
|
/// </summary>
|
|
/// <param name="context">The context.</param>
|
|
/// <param name="sessionId">The session identifier.</param>
|
|
/// <param name="deleteSubscriptions">if set to <c>true</c> subscriptions are to be deleted.</param>
|
|
[Obsolete("Use CloseSessionAsync instead.")]
|
|
void CloseSession(OperationContext context, NodeId sessionId, bool deleteSubscriptions);
|
|
|
|
/// <summary>
|
|
/// Closes the specified session.
|
|
/// </summary>
|
|
/// <param name="context">The context.</param>
|
|
/// <param name="sessionId">The session identifier.</param>
|
|
/// <param name="deleteSubscriptions">if set to <c>true</c> subscriptions are to be deleted.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
ValueTask CloseSessionAsync(
|
|
OperationContext context,
|
|
NodeId sessionId,
|
|
bool deleteSubscriptions,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Deletes the specified subscription.
|
|
/// </summary>
|
|
/// <param name="subscriptionId">The subscription identifier.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
ValueTask DeleteSubscriptionAsync(uint subscriptionId, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Called by any component to report a global event.
|
|
/// </summary>
|
|
/// <param name="e">The event.</param>
|
|
void ReportEvent(IFilterTarget e);
|
|
|
|
/// <summary>
|
|
/// Called by any component to report a global event.
|
|
/// </summary>
|
|
/// <param name="context">The context.</param>
|
|
/// <param name="e">The event.</param>
|
|
void ReportEvent(ISystemContext context, IFilterTarget e);
|
|
|
|
/// <summary>
|
|
/// Refreshes the conditions for the specified subscription.
|
|
/// </summary>
|
|
/// <param name="context">The context.</param>
|
|
/// <param name="subscriptionId">The subscription identifier.</param>
|
|
void ConditionRefresh(OperationContext context, uint subscriptionId);
|
|
|
|
/// <summary>
|
|
/// Refreshes the conditions for the specified subscription and monitored item.
|
|
/// </summary>
|
|
/// <param name="context">The context.</param>
|
|
/// <param name="subscriptionId">The subscription identifier.</param>
|
|
/// <param name="monitoredItemId">The monitored item identifier.</param>
|
|
void ConditionRefresh2(OperationContext context, uint subscriptionId, uint monitoredItemId);
|
|
|
|
/// <summary>
|
|
/// Sets the EventManager, the ResourceManager, the RequestManager and the AggregateManager.
|
|
/// </summary>
|
|
/// <param name="eventManager">The event manager.</param>
|
|
/// <param name="resourceManager">The resource manager.</param>
|
|
/// <param name="requestManager">The request manager.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
ValueTask CreateServerObjectAsync(
|
|
EventManager eventManager,
|
|
ResourceManager resourceManager,
|
|
RequestManager requestManager,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Stores the MasterNodeManager and the CoreNodeManager
|
|
/// </summary>
|
|
/// <param name="nodeManager">The node manager.</param>
|
|
void SetNodeManager(IMasterNodeManager nodeManager);
|
|
|
|
/// <summary>
|
|
/// Stores the MainNodeManagerFactory
|
|
/// </summary>
|
|
/// <param name="mainNodeManagerFactory">The main node manager factory.</param>
|
|
void SetMainNodeManagerFactory(IMainNodeManagerFactory mainNodeManagerFactory);
|
|
|
|
/// <summary>
|
|
/// Stores the SessionManager, the SubscriptionManager in the datastore.
|
|
/// </summary>
|
|
/// <param name="sessionManager">The session manager.</param>
|
|
/// <param name="subscriptionManager">The subscription manager.</param>
|
|
void SetSessionManager(
|
|
ISessionManager sessionManager,
|
|
ISubscriptionManager subscriptionManager);
|
|
|
|
/// <summary>
|
|
/// Stores the MonitoredItemQueueFactory in the datastore.
|
|
/// </summary>
|
|
/// <param name="monitoredItemQueueFactory">The MonitoredItemQueueFactory.</param>
|
|
void SetMonitoredItemQueueFactory(IMonitoredItemQueueFactory monitoredItemQueueFactory);
|
|
|
|
/// <summary>
|
|
/// Stores the Subscriptionstore in the datastore.
|
|
/// </summary>
|
|
/// <param name="subscriptionStore">The subscriptionstore.</param>
|
|
void SetSubscriptionStore(ISubscriptionStore subscriptionStore);
|
|
|
|
/// <summary>
|
|
/// Replaces the role manager with a custom <see cref="IRoleManager"/>
|
|
/// implementation. Must be called before the diagnostics node manager
|
|
/// binds the address space (typically before <c>StartServer</c>).
|
|
/// Integrators use this to plug a persistent backing store, an LDAP
|
|
/// directory, etc., in place of the default in-memory
|
|
/// <see cref="Server.RoleManager"/>.
|
|
/// </summary>
|
|
/// <param name="roleManager">The role manager to use.</param>
|
|
void SetRoleManager(IRoleManager roleManager);
|
|
|
|
/// <summary>
|
|
/// Replaces the identity registry with a custom
|
|
/// <see cref="IServerIdentityRegistry"/> implementation. Must be
|
|
/// called before sessions are activated so authenticators can run
|
|
/// ahead of the legacy impersonation event.
|
|
/// </summary>
|
|
/// <param name="registry">The identity registry to use.</param>
|
|
void SetIdentityRegistry(IServerIdentityRegistry registry);
|
|
|
|
/// <summary>
|
|
/// Replaces the user-management facade with a custom
|
|
/// <see cref="UserManagement.IUserManagement"/>
|
|
/// implementation. Must be called before the configuration node
|
|
/// manager binds the address space (typically before <c>StartServer</c>).
|
|
/// </summary>
|
|
/// <param name="userManagement">The user-management facade.</param>
|
|
void SetUserManagement(UserManagement.IUserManagement userManagement);
|
|
|
|
/// <summary>
|
|
/// Stores the AggregateManager in the datastore.
|
|
/// </summary>
|
|
/// <param name="aggregateManager">The AggregateManager.</param>
|
|
void SetAggregateManager(AggregateManager aggregateManager);
|
|
|
|
/// <summary>
|
|
/// Stores the ModellingRulesManager in the datastore.
|
|
/// </summary>
|
|
/// <param name="modellingRulesManager">The ModellingRulesManager.</param>
|
|
void SetModellingRulesManager(ModellingRulesManager modellingRulesManager);
|
|
|
|
/// <summary>
|
|
/// Updates the server status safely.
|
|
/// </summary>
|
|
/// <param name="action">Action to perform on the server status object.</param>
|
|
void UpdateServerStatus(Action<ServerStatusValue> action);
|
|
}
|
|
}
|