/* ======================================================================== * 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.Collections.Generic; using System.Linq; using Opc.Ua.Server; namespace Opc.Ua.Gds.Server { /// /// The supported roles in a GDS server. /// public class GdsRole : Role { /// /// This Role grants rights to register, update and unregister any /// OPC UA Application. /// public static Role DiscoveryAdmin { get; } = new( ObjectIds.WellKnownRole_DiscoveryAdmin, BrowseNames.WellKnownRole_DiscoveryAdmin); /// /// Certificate authority administration role. This Role grants rights /// to manage the Certificate Authority, e.g. to create and revoke /// certificates, manage trust lists, and configure certificate policies. /// public static Role CertificateAuthorityAdmin { get; } = new( ObjectIds.WellKnownRole_CertificateAuthorityAdmin, BrowseNames.WellKnownRole_CertificateAuthorityAdmin); /// /// This role grants rights to manage the Registration Authority, e.g. /// to approve or reject application registration requests, and to manage the /// Registration Authority. /// public static Role RegistrationAuthorityAdmin { get; } = new( ObjectIds.WellKnownRole_RegistrationAuthorityAdmin, BrowseNames.WellKnownRole_RegistrationAuthorityAdmin); /// /// A privilege to manage the own Certificates and pull trust list. /// /// /// Per OPC 10000-12 §7.2 the ApplicationSelfAdmin privilege grants a /// Client access only to the Application whose /// ApplicationInstance Certificate was used to establish the /// SecureChannel. /// public static Role ApplicationSelfAdmin { get; } = new( ExpandedNodeId.Null, "ApplicationSelfAdmin"); /// /// A privilege to manage one or more Applications administered by a /// configuration tool or agent. /// /// /// Per OPC 10000-12 §7.2 the ApplicationAdmin privilege grants a /// Client access to a configurable set of Applications. The set of /// administered ApplicationIds is carried by the /// /// property assigned during impersonation. /// public static Role ApplicationAdmin { get; } = new( ExpandedNodeId.Null, "ApplicationAdmin"); public GdsRole(NodeId roleId, string name) : base(roleId, name) { } } /// /// RoleBasedIdentity with additional Properties ApplicationId and /// AdministeredApplicationIds. /// public class GdsRoleBasedIdentity : RoleBasedIdentity { public GdsRoleBasedIdentity( IUserIdentity identity, IEnumerable roles, NodeId applicationId, NamespaceTable namespaces) : this(identity, roles, applicationId, null, namespaces) { } public GdsRoleBasedIdentity( IUserIdentity identity, IEnumerable roles, NamespaceTable namespaces) : this(identity, roles, default, null, namespaces) { } /// /// Creates a new identity that carries an /// binding and/or an /// binding. /// /// The wrapped user identity. /// The roles granted to the identity. /// /// The ApplicationId associated with the /// privilege, or /// if not applicable. /// /// /// The set of ApplicationIds administered via the /// privilege, or null if /// not applicable. /// /// The namespace table. public GdsRoleBasedIdentity( IUserIdentity identity, IEnumerable roles, NodeId applicationId, IEnumerable? administeredApplicationIds, NamespaceTable namespaces) : base(identity, roles, namespaces) { ApplicationId = applicationId; AdministeredApplicationIds = administeredApplicationIds == null ? [] : [.. administeredApplicationIds]; } /// /// The applicationId in case the ApplicationSelfAdminPrivilege is used. /// public NodeId ApplicationId { get; } /// /// The set of ApplicationIds administered by an /// bearer. /// public IReadOnlyList AdministeredApplicationIds { get; } /// /// /// Overridden to return a so that /// , /// and the concrete type are /// preserved when additional roles (e.g. /// ) are layered on. /// public override RoleBasedIdentity WithAdditionalRoles( IEnumerable additionalRoles, NamespaceTable namespaces) { return new GdsRoleBasedIdentity( InnerIdentity, Roles.Concat(additionalRoles), ApplicationId, AdministeredApplicationIds, namespaces); } } }