/* ========================================================================
* 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.Threading;
using System.Threading.Tasks;
using Opc.Ua.Security.Certificates;
namespace Opc.Ua.Server
{
///
/// A generic session manager object for a server.
///
public interface ISession : IDisposable
{
///
/// Whether the session has been activated.
///
bool Activated { get; }
///
/// The server application instance certificate used by this session.
///
Certificate ServerCertificate { get; }
///
/// The application instance certificate associated with the client.
///
Certificate ClientCertificate { get; }
///
/// The last time the session was contacted by the client.
///
DateTime ClientLastContactTime { get; }
///
/// The monotonic tick count (milliseconds) at the last client contact.
/// Used for timeout calculations that are immune to system time changes.
///
long LastContactTickCount { get; }
///
/// The client Nonce associated with the session.
///
ByteString ClientNonce { get; }
///
/// A lock which must be acquired before accessing the diagnostics.
///
object DiagnosticsLock { get; }
///
/// The application defined mapping for user identity provided by the client.
///
IUserIdentity EffectiveIdentity { get; }
///
/// Whether the session's has been
/// invalidated by a configuration change (e.g. Role identity-mapping
/// rules) and should be recomputed on the next request.
///
///
/// The flag is set by and cleared by
/// . Per OPC UA Part 18 §4.4.1
/// role grants must reflect the live RoleSet without forcing the
/// client to re-activate.
///
bool IsIdentityStale { get; }
///
/// Marks the session's as stale so
/// the next request triggers a re-evaluation of the role mapping.
///
///
/// Safe to call from any thread. Multiple concurrent calls are
/// idempotent — the flag is sticky until a refresh clears it.
///
void MarkIdentityStale();
///
/// Atomically replaces the session's
/// with the supplied value and clears the
/// flag.
///
///
/// The newly resolved effective identity (including any roles layered
/// on by mandatory-role assignment and the live RoleSet).
///
void RefreshEffectiveIdentity(IUserIdentity effectiveIdentity);
///
/// Returns the session's endpoint
///
EndpointDescription EndpointDescription { get; }
///
/// Whether the session timeout has elapsed since the last communication from the client.
///
bool HasExpired { get; }
///
/// Gets the identifier assigned to the session when it was created.
///
NodeId Id { get; }
///
/// The user identity provided by the client.
///
IUserIdentity Identity { get; }
///
/// The user identity token provided by the client wrapped into a handler.
///
IUserIdentityTokenHandler IdentityToken { get; }
///
/// The locales requested when the session was created.
///
string[] PreferredLocales { get; }
///
/// Returns the session's SecureChannelId
///
string SecureChannelId { get; }
///
/// The diagnostics associated with the session.
///
SessionDiagnosticsDataType SessionDiagnostics { get; }
///
/// Activates the session and binds it to the current secure channel.
///
bool Activate(
OperationContext context,
IUserIdentityTokenHandler identityToken,
IUserIdentity identity,
IUserIdentity effectiveIdentity,
ArrayOf localeIds,
Nonce serverNonce);
///
/// Closes a session and removes itself from the address space.
///
ValueTask CloseAsync(CancellationToken cancellationToken = default);
///
/// Create new ECC ephemeral key
///
/// A new ephemeral key
EphemeralKeyType? GetNewEphemeralKey();
///
/// Checks if the secure channel is currently valid.
///
bool IsSecureChannelValid(string secureChannelId);
///
/// Restores a continuation point for a session.
///
///
/// The caller is responsible for disposing the continuation point returned.
///
ContinuationPoint? RestoreContinuationPoint(ByteString continuationPoint);
///
/// Restores a previously saves history continuation point.
///
/// The identifier for the continuation point.
/// The save continuation point. null if not found.
object? RestoreHistoryContinuationPoint(ByteString continuationPoint);
///
/// Saves a continuation point for a session.
///
///
/// If the session has too many continuation points the oldest one is dropped.
///
void SaveContinuationPoint(ContinuationPoint continuationPoint);
///
/// Saves a continuation point used for historical reads.
///
/// The identifier for the continuation point.
/// The continuation point.
///
/// If the continuationPoint implements IDisposable it will be disposed when
/// the Session is closed or discarded.
///
void SaveHistoryContinuationPoint(Guid id, object continuationPoint);
///
/// Set the ECC security policy URI
///
void SetUserTokenSecurityPolicy(string securityPolicyUri);
///
/// Updates the requested locale ids.
///
/// true if the new locale ids are different from the old locale ids.
bool UpdateLocaleIds(ArrayOf localeIds);
///
/// Activates the session and binds it to the current secure channel.
///
void ValidateBeforeActivate(
OperationContext context,
SignatureData clientSignature,
ExtensionObject userIdentityToken,
SignatureData userTokenSignature,
out IUserIdentityTokenHandler? identityToken,
out UserTokenPolicy? userTokenPolicy);
///
/// Validate the diagnostic info.
///
void ValidateDiagnosticInfo(RequestHeader requestHeader);
///
/// Validates the request.
///
void ValidateRequest(RequestHeader requestHeader, SecureChannelContext secureChannelContext, RequestType requestType);
}
}