Add authentication and role-based write access control
Implements configurable user authentication (anonymous + username/password) with pluggable credential provider (IUserAuthenticationProvider). Anonymous writes can be disabled via AnonymousCanWrite setting while reads remain open. Adds -U/-P flags to all CLI commands for authenticated sessions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,12 @@ public class WriteCommand : ICommand
|
||||
[CommandOption("url", 'u', Description = "OPC UA server endpoint URL", IsRequired = true)]
|
||||
public string Url { get; init; } = default!;
|
||||
|
||||
[CommandOption("username", 'U', Description = "Username for authentication")]
|
||||
public string? Username { get; init; }
|
||||
|
||||
[CommandOption("password", 'P', Description = "Password for authentication")]
|
||||
public string? Password { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the node identifier that should receive the write.
|
||||
/// </summary>
|
||||
@@ -33,7 +39,7 @@ public class WriteCommand : ICommand
|
||||
/// <param name="console">The console used to report the write result.</param>
|
||||
public async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
using var session = await OpcUaHelper.ConnectAsync(Url);
|
||||
using var session = await OpcUaHelper.ConnectAsync(Url, Username, Password);
|
||||
|
||||
var node = new NodeId(NodeId);
|
||||
var current = await session.ReadValueAsync(node);
|
||||
|
||||
Reference in New Issue
Block a user