Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
</CertificateGroupConfiguration>
</CertificateGroups>
<KnownHostNames />
<DatabaseStorePath>%LocalApplicationData%/OPC Foundation/GDS/gdsdb.json</DatabaseStorePath>
<DatabaseStorePath></DatabaseStorePath>
</GlobalDiscoveryServerConfiguration>
</ua:XmlElement>
<ua:XmlElement>
Expand Down
4 changes: 3 additions & 1 deletion Applications/ConsoleReferenceServer/GdsNodeManagerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public INodeManager Create(IServerInternal server, ApplicationConfiguration conf
Directory.CreateDirectory(databaseDir);
}

var database = JsonApplicationsDatabase.Load(databaseStorePath);
LinqApplicationsDatabase database = string.IsNullOrEmpty(databaseDir)
? new LinqApplicationsDatabase()
: new JsonApplicationsDatabase(databaseStorePath);

return new ApplicationsNodeManager(
server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@
</CertificateGroupConfiguration>
</CertificateGroups>
<KnownHostNames />
<DatabaseStorePath>%LocalApplicationData%/OPC Foundation/GDS/gdsdb.json</DatabaseStorePath>
<DatabaseStorePath></DatabaseStorePath>
</GlobalDiscoveryServerConfiguration>
</ua:XmlElement>
<ua:XmlElement>
Expand Down
16 changes: 8 additions & 8 deletions Applications/UAReferenceServer.ctt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16799,7 +16799,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="user1"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -16843,7 +16843,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="password"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -16887,7 +16887,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="DiscoveryAdmin"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -16931,7 +16931,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="demo"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -16975,7 +16975,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="user1"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -17019,7 +17019,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="password"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -17063,7 +17063,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="sysadmin"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down Expand Up @@ -17107,7 +17107,7 @@
</Column>
<Column column="1">
<ItemData role="0" rolename="DisplayRole">
<Value type="10" typename="QString" data=""/>
<Value type="10" typename="QString" data="demo"/>
</ItemData>
<ChildRows size="0"/>
</Column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Opc.Ua.Security;
using Opc.Ua.Types;

namespace Opc.Ua.Gds.Server.Database
{
Expand Down Expand Up @@ -115,7 +117,9 @@ public virtual NodeId RegisterApplication(ApplicationRecordDataType application)

if (application.ServerCapabilities.IsEmpty)
{
application.ServerCapabilities = ["NA"];
throw new ArgumentException(
"At least one ServerCapability must be provided.",
nameof(application));
}
}
else if (!application.DiscoveryUrls.IsEmpty)
Expand Down Expand Up @@ -161,6 +165,11 @@ public virtual ApplicationRecordDataType GetApplication(NodeId applicationId)

public virtual ApplicationRecordDataType[] FindApplications(string applicationUri)
{
if (string.IsNullOrWhiteSpace(applicationUri))
{
throw new ServiceResultException(
StatusCodes.BadInvalidArgument);
}
return null;
}

Expand Down Expand Up @@ -190,6 +199,20 @@ public virtual ApplicationDescription[] QueryApplications(
{
lastCounterResetTime = DateTimeUtc.MinValue;
nextRecordId = 0;

if (applicationType > 2)
{
throw new ServiceResultException(
StatusCodes.BadInvalidArgument);
}

if (serverCapabilities.Contains("NA", StringComparer.OrdinalIgnoreCase) &&
serverCapabilities.Count > 1)
{
throw new ServiceResultException(
StatusCodes.BadInvalidArgument);
}

return null;
}

Expand Down Expand Up @@ -332,7 +355,7 @@ protected Guid GetNodeIdGuid(NodeId nodeId)
if (NamespaceIndex != nodeId.NamespaceIndex ||
!nodeId.TryGetValue(out Guid id))
{
throw new ServiceResultException(StatusCodes.BadNodeIdUnknown);
throw new ServiceResultException(StatusCodes.BadNotFound);
}

return id;
Expand Down Expand Up @@ -367,7 +390,7 @@ protected void ValidateApplicationNodeId(NodeId nodeId)
if ((nodeId.IdType != IdType.Guid && nodeId.IdType != IdType.String) ||
NamespaceIndex != nodeId.NamespaceIndex)
{
throw new ServiceResultException(StatusCodes.BadNodeIdUnknown);
throw new ServiceResultException(StatusCodes.BadNotFound);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public override void Initialize()

public override NodeId RegisterApplication(ApplicationRecordDataType application)
{
bool isNewEntry = application.ApplicationId.IsNull;
NodeId appNodeId = base.RegisterApplication(application);
if (appNodeId.IsNull)
{
Expand All @@ -119,19 +120,36 @@ public override NodeId RegisterApplication(ApplicationRecordDataType application

lock (Lock)
{
bool existingApplication = (
from ii in Applications
where ii.ApplicationUri == application.ApplicationUri
select ii
).Any();

if (existingApplication && isNewEntry)
{
throw new ServiceResultException(
StatusCodes.BadEntryExists,
"An application with the same application URI is already registered.");
}

Application record = null;

if (applicationId != Guid.Empty)
{
IEnumerable<Application> results =
from ii in Applications
record =
(from ii in Applications
where ii.ApplicationId == applicationId
select ii;

record = results.SingleOrDefault();
select ii).SingleOrDefault();

if (record != null)
{
if (record.ApplicationUri != application.ApplicationUri)
{
throw new ServiceResultException(
StatusCodes.BadWriteNotSupported);
}

var endpoints = (
from ii in ServerEndpoints
where ii.ApplicationId == record.ApplicationId
Expand Down Expand Up @@ -221,9 +239,9 @@ public override void UnregisterApplication(NodeId applicationId)
Application application =
(from ii in Applications where ii.ApplicationId == id select ii)
.SingleOrDefault()
?? throw new ArgumentException(
"A record with the specified application id does not exist.",
nameof(applicationId));
?? throw new ServiceResultException(
StatusCodes.BadNotFound,
"A record with the specified application id does not exist.");

IEnumerable<CertificateRequest> certificateRequests =
from ii in CertificateRequests
Expand Down Expand Up @@ -323,6 +341,8 @@ from ii in ServerEndpoints

public override ApplicationRecordDataType[] FindApplications(string applicationUri)
{
base.FindApplications(applicationUri);

lock (Lock)
{
IEnumerable<Application> results =
Expand Down Expand Up @@ -495,6 +515,7 @@ from ii in ServerEndpoints
{
if (maxRecordsToReturn != 0 && records.Count >= maxRecordsToReturn)
{
nextRecordId = result.ID + 1;
break;
}

Expand Down Expand Up @@ -524,7 +545,6 @@ from ii in ApplicationNames
DiscoveryProfileUri = null,
DiscoveryUrls = discoveryUrls
});
nextRecordId = lastID + 1;
}
return [.. records];
}
Expand Down
38 changes: 33 additions & 5 deletions Libraries/Opc.Ua.Gds.Server.Common/ApplicationsNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ApplicationsNodeManager(
ApplicationConfiguration configuration,
IApplicationsDatabase database,
ICertificateRequest request,
ICertificateGroup certificateGroup,
ICertificateGroup certificateGroupFactory,
bool autoApprove = false)
: base(
server,
Expand Down Expand Up @@ -105,7 +105,7 @@ public ApplicationsNodeManager(
m_autoApprove = autoApprove;
m_database = database;
m_request = request;
m_certificateGroupFactory = certificateGroup;
m_certificateGroupFactory = certificateGroupFactory;
m_certificateGroups = [];

try
Expand Down Expand Up @@ -652,7 +652,14 @@ private ServiceResult OnRegisterApplication(

m_logger.LogInformation("OnRegisterApplication: {ApplicationUri}", application.ApplicationUri);

applicationId = m_database.RegisterApplication(application);
try
{
applicationId = m_database.RegisterApplication(application);
}
catch (ArgumentException ex)
{
throw new ServiceResultException(StatusCodes.BadInvalidArgument, ex);
}

if (!applicationId.IsNull)
{
Expand Down Expand Up @@ -687,7 +694,14 @@ private ServiceResult OnUpdateApplication(
LocalizedText.From("The application id does not exist."));
}

m_database.RegisterApplication(application);
try
{
m_database.RegisterApplication(application);
}
catch (ArgumentException ex)
{
throw new ServiceResultException(StatusCodes.BadInvalidArgument, ex);
}

ArrayOf<Variant> inputArguments = [Variant.FromStructure(application)];
Server.ReportApplicationRegistrationChangedAuditEvent(
Expand Down Expand Up @@ -806,6 +820,7 @@ private ServiceResult OnFindApplications(
{
AuthorizationHelper.HasAuthorization(context, AuthorizationHelper.AuthenticatedUser);
m_logger.LogInformation("OnFindApplications: {ApplicationUri}", applicationUri);

applications = m_database.FindApplications(applicationUri);
return ServiceResult.Good;
}
Expand All @@ -822,7 +837,20 @@ private ServiceResult OnGetApplication(
AuthorizationHelper.AuthenticatedUserOrSelfAdmin,
applicationId);
m_logger.LogInformation("OnGetApplication: {ApplicationId}", applicationId);
application = m_database.GetApplication(applicationId);

try
{
application = m_database.GetApplication(applicationId);
}
catch (ArgumentException ex)
{
throw new ServiceResultException(StatusCodes.BadInvalidArgument, ex);
}

if (application == null)
{
throw new ServiceResultException(StatusCodes.BadNotFound);
}
return ServiceResult.Good;
}

Expand Down
17 changes: 12 additions & 5 deletions Libraries/Opc.Ua.Gds.Server.Common/Diagnostics/AuditEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal static void ReportCertificateDeliveredAuditEvent(
e.SetChildValue(
systemContext,
Ua.BrowseNames.SourceName,
"Method/UpdateCertificate",
"Method/FinishRequest",
false);
e.SetChildValue(
systemContext,
Expand Down Expand Up @@ -148,7 +148,7 @@ internal static void ReportCertificateRequestedAuditEvent(
e.SetChildValue(
systemContext,
Ua.BrowseNames.SourceName,
"Method/UpdateCertificate",
"Method/StartNewKeyPairRequest",
false);
e.SetChildValue(
systemContext,
Expand Down Expand Up @@ -180,7 +180,7 @@ internal static void ReportCertificateRequestedAuditEvent(
{
logger.LogError(
ex,
"Error while reporting CertificateDeliveredAuditEventState event.");
"Error while reporting CertificateRequestedAuditEventState event.");
}
}

Expand Down Expand Up @@ -216,14 +216,21 @@ internal static void ReportApplicationRegistrationChangedAuditEvent(
e.SetChildValue(
systemContext,
Ua.BrowseNames.SourceName,
"Method/UpdateCertificate",
"Method/RegisterApplication",
false);

e.SetChildValue(
systemContext,
Ua.BrowseNames.LocalTime,
TimeZoneDataType.Local,
false);

e.SetChildValue(
systemContext,
Ua.BrowseNames.ActionTimeStamp,
DateTimeUtc.Now,
false);

e.SetChildValue(systemContext, Ua.BrowseNames.MethodId, method?.NodeId ?? default, false);
e.SetChildValue(
systemContext,
Expand All @@ -237,7 +244,7 @@ internal static void ReportApplicationRegistrationChangedAuditEvent(
{
logger.LogError(
ex,
"Error while reporting CertificateDeliveredAuditEventState event.");
"Error while reporting ApplicationRegistrationChangedAuditEventState event.");
}
}
}
Expand Down
Loading
Loading