Skip to content

Commit a8ca36a

Browse files
authored
Merge pull request CactuseSecurity#3216 from tpurschke/develop
improve exception handling
2 parents 01ecc64 + 6e3a686 commit a8ca36a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

roles/middleware/files/FWO.Middleware.Server/AppDataImport.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task<bool> Run()
5151
try
5252
{
5353
NamingConvention = JsonSerializer.Deserialize<ModellingNamingConvention>(globalConfig.ModNamingConvention) ?? new();
54-
List<string> importfilePathAndNames = JsonSerializer.Deserialize<List<string>>(globalConfig.ImportAppDataPath) ?? throw new Exception("Config Data could not be deserialized.");
54+
List<string> importfilePathAndNames = JsonSerializer.Deserialize<List<string>>(globalConfig.ImportAppDataPath) ?? throw new JsonException("Config Data could not be deserialized.");
5555
userConfig = new(globalConfig);
5656
userConfig.User.Name = Roles.MiddlewareServer;
5757
userConfig.AutoReplaceAppServer = globalConfig.AutoReplaceAppServer;
@@ -76,8 +76,8 @@ public async Task<bool> Run()
7676
private async Task InitLdap()
7777
{
7878
connectedLdaps = await apiConnection.SendQueryAsync<List<Ldap>>(AuthQueries.getLdapConnections);
79-
internalLdap = connectedLdaps.FirstOrDefault(x => x.IsInternal() && x.HasGroupHandling()) ?? throw new Exception("No internal Ldap with group handling found.");
80-
ownerGroupLdap = connectedLdaps.FirstOrDefault(x => x.Id == globalConfig.OwnerLdapId) ?? throw new Exception("Ldap with group handling not found.");
79+
internalLdap = connectedLdaps.FirstOrDefault(x => x.IsInternal() && x.HasGroupHandling()) ?? throw new KeyNotFoundException("No internal Ldap with group handling found.");
80+
ownerGroupLdap = connectedLdaps.FirstOrDefault(x => x.Id == globalConfig.OwnerLdapId) ?? throw new KeyNotFoundException("Ldap with group handling not found.");
8181
modellerRoleDn = $"cn=modeller,{internalLdap.RoleSearchPath}";
8282
requesterRoleDn = $"cn=requester,{internalLdap.RoleSearchPath}";
8383
implementerRoleDn = $"cn=implementer,{internalLdap.RoleSearchPath}";
@@ -102,7 +102,7 @@ private async Task<bool> ImportSingleSource(string importfileName)
102102
try
103103
{
104104
ReadFile(importfileName);
105-
ModellingImportOwnerData? importedOwnerData = JsonSerializer.Deserialize<ModellingImportOwnerData>(importFile) ?? throw new Exception("File could not be parsed.");
105+
ModellingImportOwnerData? importedOwnerData = JsonSerializer.Deserialize<ModellingImportOwnerData>(importFile) ?? throw new JsonException("File could not be parsed.");
106106
if (importedOwnerData != null && importedOwnerData.Owners != null)
107107
{
108108
importedApps = importedOwnerData.Owners;
@@ -301,7 +301,7 @@ private string GetGroupDn(string extAppIdString)
301301
{
302302
if (ownerGroupLdapPath == null)
303303
{
304-
throw new Exception("Owner group LDAP path is not set.");
304+
throw new ArgumentNullException(nameof(ownerGroupLdapPath));
305305
}
306306
return $"cn={GetGroupName(extAppIdString)},{ownerGroupLdapPath}";
307307
}
@@ -425,7 +425,7 @@ private async Task<string> CreateUserGroup(ModellingImportAppData incomingApp)
425425

426426
private async Task<string> UpdateUserGroup(ModellingImportAppData incomingApp, string groupDn)
427427
{
428-
List<string> existingMembers = (allGroups.FirstOrDefault(x => x.GroupDn == groupDn) ?? throw new Exception("Group could not be found.")).Members;
428+
List<string> existingMembers = (allGroups.FirstOrDefault(x => x.GroupDn == groupDn) ?? throw new KeyNotFoundException($"Group with DN '{groupDn}' could not be found.")).Members;
429429
if (incomingApp.Modellers != null)
430430
{
431431
foreach (var modeller in incomingApp.Modellers)

0 commit comments

Comments
 (0)