/* ========================================================================
* 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;
namespace Opc.Ua.Server.UserManagement
{
///
/// Event payload raised by
/// when a ModifyUser(Disabled=true) or RemoveUser mutator
/// completes. The binding layer subscribes to this event to close all
/// active sessions associated with the user per Part 18 §5.2.6 / §5.2.7.
///
public sealed class UserDeactivatedEventArgs : EventArgs
{
///
/// Initializes the event payload.
///
public UserDeactivatedEventArgs(string userName)
{
UserName = userName;
}
///
/// The user that was disabled or removed.
///
public string UserName { get; }
}
///
/// Server-side facade over the OPC UA Part 18 §5 user-management model.
/// Backs the standard ServerConfiguration.UserManagement object
/// (NodeId i=24290) and is bound to its AddUser, ModifyUser,
/// RemoveUser and ChangePassword methods by
/// .
///
///
/// The default implementation wraps the
/// existing for
/// credential persistence and stores the user metadata
/// ( + description) in memory.
/// Integrators that need to persist metadata across server restarts can
/// implement this interface directly and inject the instance via
/// .
///
public interface IUserManagement
{
///
/// Allowed password length per Part 18 §5.2.1 (mandatory).
///
Range PasswordLength { get; }
///
/// Password feature requirements per Part 18 §5.2.1 (mandatory).
///
PasswordOptionsMask PasswordOptions { get; }
///
/// Optional human-readable password restrictions per Part 18 §5.2.1.
///
LocalizedText? PasswordRestrictions { get; }
///
/// Read-only snapshot of all configured users.
///
IReadOnlyList SnapshotUsers();
///
/// Adds a user per Part 18 §5.2.5.
///
///
/// Good on success;
/// Bad_AlreadyExists if the user already exists;
/// Bad_OutOfRange if the password violates
/// or the character-class requirements in ;
/// Bad_NotSupported if has
/// flags the server does not support;
/// Bad_ConfigurationError if
/// combines incompatible flags (e.g. MustChangePassword + NoChangeByUser).
///
ServiceResult AddUser(
string userName,
string password,
UserConfigurationMask userConfiguration,
string description);
///
/// Modifies a user per Part 18 §5.2.6.
/// is the user name of the calling session, used to enforce the
/// Bad_InvalidSelfReference rule when the modify operation
/// disables the calling user.
///
/// Name of the user to modify.
/// Whether is meaningful.
/// New password (ignored when is false).
/// Whether is meaningful.
/// New configuration mask (ignored when is false).
/// Whether is meaningful.
/// New description (ignored when is false).
/// The user name of the calling session, or null for non-user callers.
ServiceResult ModifyUser(
string userName,
bool modifyPassword,
string password,
bool modifyUserConfiguration,
UserConfigurationMask userConfiguration,
bool modifyDescription,
string description,
string? callingUserName);
///
/// Removes a user per Part 18 §5.2.7.
/// is used to enforce the Bad_InvalidSelfReference rule.
///
/// Name of the user to remove.
/// The user name of the calling session, or null for non-user callers.
ServiceResult RemoveUser(string userName, string? callingUserName);
///
/// Changes a user's password per Part 18 §5.2.8. Self-service only —
/// the binding ensures matches the calling
/// session's USERNAME identity token.
///
ServiceResult ChangePassword(string userName, string oldPassword, string newPassword);
///
/// Returns true if the user exists and has the
/// bit set.
/// Used by the ActivateSession flow to grant only the
/// Anonymous role until the user changes their password.
///
bool MustChangePassword(string userName);
///
/// Returns true if the user exists and is not disabled.
///
bool IsUserActive(string userName);
///
/// Raised after a ModifyUser(Disabled=true) or
/// RemoveUser succeeds so the binding layer can close any
/// active sessions for that user per Part 18 §5.2.6 / §5.2.7.
///
event EventHandler? UserDeactivated;
}
}