Skip to content

Commit f8d41f2

Browse files
authored
Merge pull request CactuseSecurity#3086 from SolidProgramming/issue_3062
Merge: Modelling - no NA should be usable for selected interfaces
2 parents 5bf0634 + c35061d commit f8d41f2

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

roles/database/files/sql/idempotent/fworch-texts.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,12 +1156,6 @@ INSERT INTO txt VALUES ('add_interface', 'German', 'Schnittstelle hinzuf&uu
11561156
INSERT INTO txt VALUES ('add_interface', 'English', 'Add Interface');
11571157
INSERT INTO txt VALUES ('edit_interface', 'German', 'Schnittstelle bearbeiten');
11581158
INSERT INTO txt VALUES ('edit_interface', 'English', 'Edit Interface');
1159-
INSERT INTO txt VALUES ('interface_contain_nwarea','German','Schnittstellen dürfen keine Netzbereiche enthalten');
1160-
INSERT INTO txt VALUES ('interface_contain_nwarea','English','Interfaces must not contain network areas');
1161-
INSERT INTO txt VALUES ('direction_contain_nwarea','German','Quelle und Ziel dürfen nicht gleichzeitig einen Netzbereich enthalten');
1162-
INSERT INTO txt VALUES ('direction_contain_nwarea','English','Source and destination must not contain a network area at the same time');
1163-
INSERT INTO txt VALUES ('only_common_service', 'German', 'Dieser Netzbereich kann nur in der Registerkarte Gemeinsame Dienste verwendet werden.');
1164-
INSERT INTO txt VALUES ('only_common_service', 'English', 'This network area can only be used in common services tab');
11651159
INSERT INTO txt VALUES ('delete_interface', 'German', 'Schnittstelle löschen');
11661160
INSERT INTO txt VALUES ('delete_interface', 'English', 'Delete Interface');
11671161
INSERT INTO txt VALUES ('insert_forbidden', 'German', 'Einfügen verboten');
@@ -2867,6 +2861,14 @@ INSERT INTO txt VALUES ('U9019', 'German', 'Sind sie sicher, dass sie die Exter
28672861
INSERT INTO txt VALUES ('U9019', 'English', 'Are you sure you want to reinit the external requests for following ticket: ');
28682862
INSERT INTO txt VALUES ('U9020', 'German', 'Die externe Beantragung wurde gestartet.');
28692863
INSERT INTO txt VALUES ('U9020', 'English', 'External Request initialized.');
2864+
INSERT INTO txt VALUES ('U9021', 'German', 'Schnittstellen dürfen keine Netzbereiche enthalten');
2865+
INSERT INTO txt VALUES ('U9021', 'English', 'Interfaces must not contain network areas');
2866+
INSERT INTO txt VALUES ('U9022', 'German', 'Quelle und Ziel dürfen nicht gleichzeitig einen Netzbereich enthalten');
2867+
INSERT INTO txt VALUES ('U9022', 'English', 'Source and destination must not contain a network area at the same time');
2868+
INSERT INTO txt VALUES ('U9023', 'German', 'Dieser Netzbereich kann nur in der Registerkarte Gemeinsame Dienste verwendet werden.');
2869+
INSERT INTO txt VALUES ('U9023', 'English', 'This network area can only be used in common services tab');
2870+
INSERT INTO txt VALUES ('U9024', 'German', 'Netzbereiche können nicht zusammen mit Schnittstellen anderer Apps genutzt werden.');
2871+
INSERT INTO txt VALUES ('U9024', 'English', 'Network areas cannot be used together with interfaces from foreign apps.');
28702872

28712873
-- error messages
28722874
INSERT INTO txt VALUES ('E0001', 'German', 'Nicht klassifizierter Fehler: ');

roles/lib/files/FWO.Services/ModellingConnectionHandler.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,38 @@ public void AddExtraConfig()
276276
AddExtraConfigMode = true;
277277
}
278278

279+
/// <summary>
280+
/// Checks the given interface object if it can be used with network areas that are added to the connection.
281+
/// </summary>
282+
/// <param name="interf"></param>
283+
/// <returns></returns>
284+
public bool InterfaceAllowedWithNetworkArea(ModellingConnection interf)
285+
{
286+
if (!ActConn.IsInterface && !ActConn.IsCommonService && interf.AppId != ActConn.AppId &&
287+
( ActConn.DestinationAreas.Count > 0 || DstAreasToAdd.Count > 0 ||
288+
ActConn.SourceAreas.Count > 0 || SrcAreasToAdd.Count > 0 ))
289+
{
290+
return false;
291+
}
292+
293+
return true;
294+
}
295+
296+
/// <summary>
297+
/// Checks the selected interface if it is foreign to the modelled connection
298+
/// </summary>
299+
/// <returns></returns>
300+
public bool IsNotInterfaceForeignToApp()
301+
{
302+
if (!ActConn.IsInterface && !ActConn.IsCommonService && ActConn.UsedInterfaceId != null &&
303+
ActConn.UsedInterfaceId > 0 && PreselectedInterfaces.FirstOrDefault(_ => _.Id == ActConn.UsedInterfaceId)?.AppId != ActConn.AppId)
304+
{
305+
return false;
306+
}
307+
308+
return true;
309+
}
310+
279311
/// <summary>
280312
/// Checks the opposite direction if it already contains a network area.
281313
/// </summary>
@@ -314,13 +346,13 @@ public bool NetworkAreaUseAllowed(List<ModellingNetworkArea> networkAreas, Direc
314346

315347
if (IsAreaForbiddenInDirection(direction))
316348
{
317-
reason.Text = userConfig.GetText("direction_contain_nwarea");
349+
reason.Text = userConfig.GetText("U9022");
318350
return false;
319351
}
320352

321353
if (ActConn.IsInterface)
322354
{
323-
reason.Text = userConfig.GetText("interface_contain_nwarea");
355+
reason.Text = userConfig.GetText("U9021");
324356
return false;
325357
}
326358

@@ -335,7 +367,7 @@ public bool NetworkAreaUseAllowed(List<ModellingNetworkArea> networkAreas, Direc
335367
return true;
336368
}
337369

338-
reason.Text = userConfig.GetText("only_common_service");
370+
reason.Text = userConfig.GetText("U9023");
339371
return false;
340372
}
341373

roles/ui/files/FWO.UI/Pages/NetworkModelling/EditConn.razor

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@
489489
{
490490
if(Container.ConnElement != null)
491491
{
492+
if (ConnHandler is not null && !ConnHandler.InterfaceAllowedWithNetworkArea(Container.ConnElement))
493+
{
494+
DisplayMessageInUi(default, userConfig.GetText("edit_connection"), userConfig.GetText("U9024"), true);
495+
Container.Clear();
496+
return;
497+
}
498+
492499
if(ConnHandler!.ActConn.IsInterface)
493500
{
494501
await ConnHandler!.RequestReplaceInterface(Container.ConnElement);
@@ -506,6 +513,13 @@
506513
}
507514
if(Container.AreaElements.Count > 0)
508515
{
516+
if (ConnHandler is not null && !ConnHandler.IsNotInterfaceForeignToApp())
517+
{
518+
DisplayMessageInUi(default, userConfig.GetText("edit_connection"), userConfig.GetText("U9024"), true);
519+
Container.Clear();
520+
return;
521+
}
522+
509523
if (ConnHandler is not null && !ConnHandler.NetworkAreaUseAllowed(Container.AreaElements, Direction.Source, out (string Title, string Text) reason))
510524
{
511525
DisplayMessageInUi(default, reason.Title, reason.Text, true);
@@ -531,6 +545,13 @@
531545
{
532546
if(Container.ConnElement != null)
533547
{
548+
if (ConnHandler is not null && !ConnHandler.InterfaceAllowedWithNetworkArea(Container.ConnElement))
549+
{
550+
DisplayMessageInUi(default, userConfig.GetText("edit_connection"), userConfig.GetText("U9024"), true);
551+
Container.Clear();
552+
return;
553+
}
554+
534555
if(ConnHandler!.ActConn.IsInterface)
535556
{
536557
await ConnHandler!.RequestReplaceInterface(Container.ConnElement);
@@ -547,7 +568,14 @@
547568
ConnHandler?.AppRolesToDestination(Container.AppRoleElements);
548569
}
549570
if(Container.AreaElements.Count > 0)
550-
{
571+
{
572+
if (ConnHandler is not null && !ConnHandler.IsNotInterfaceForeignToApp())
573+
{
574+
DisplayMessageInUi(default, userConfig.GetText("edit_connection"), userConfig.GetText("U9024"), true);
575+
Container.Clear();
576+
return;
577+
}
578+
551579
if (ConnHandler is not null && !ConnHandler.NetworkAreaUseAllowed(Container.AreaElements, Direction.Destination, out (string Title, string Text) reason))
552580
{
553581
DisplayMessageInUi(default, reason.Title, reason.Text, true);

roles/ui/files/FWO.UI/Pages/NetworkModelling/EditConnLeftSide.razor

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@
298298

299299
private bool InterfaceToConn(ModellingConnection interf)
300300
{
301+
if (ConnHandler is not null && !ConnHandler.InterfaceAllowedWithNetworkArea(interf))
302+
{
303+
DisplayMessageInUi(default, userConfig.GetText("edit_connection"), userConfig.GetText("U9024"), true);
304+
return false;
305+
}
306+
301307
ConnHandler?.InterfaceToConn(interf);
302308
ConnHandlerChanged.InvokeAsync(ConnHandler);
303309
return true;
@@ -358,6 +364,13 @@
358364
}
359365
if(areas.Count > 0)
360366
{
367+
if (ConnHandler is not null && !ConnHandler.IsNotInterfaceForeignToApp())
368+
{
369+
DisplayMessageInUi(default, userConfig.GetText("edit_connection"), userConfig.GetText("U9024"), true);
370+
selectedNwElems = new();
371+
return;
372+
}
373+
361374
Direction direction = toSource ? Direction.Source : Direction.Destination;
362375

363376
if (ConnHandler is not null && !ConnHandler.NetworkAreaUseAllowed(areas, direction, out (string Title, string Text) reason))

0 commit comments

Comments
 (0)