public async Task ApplySecurityContractDefinitionAsync(SecurityContract securityContract, Guid updatedById, bool dryRun = false) { // Start transactions to allow complete rollback in case of an error BeginAllTransactions(); try { SecurityContractDryRunResult securityContractDryRunResult = new SecurityContractDryRunResult(); // First apply all of the application(micro-service) definitions that present within the Security Contract. // All the components of a security contract are optional, so check for this here. if (securityContract.Applications != null && securityContract.Applications.Count > 0) { foreach (var applicationSecurityContractDefinition in securityContract.Applications) { await securityContractApplicationService.ApplyResourceServerDefinitionAsync(applicationSecurityContractDefinition, updatedById, dryRun, securityContractDryRunResult); } } // Apply any clients that may be defined within the security contract. if (securityContract.Clients != null && securityContract.Clients.Count > 0) { foreach (var clientSecurityContractDefinition in securityContract.Clients) { await clientService.ApplyClientDefinitionAsync(clientSecurityContractDefinition, dryRun, securityContractDryRunResult); } } // Apply any default configurations that may be defined within the security contract. if (securityContract.DefaultConfigurations != null && securityContract.DefaultConfigurations.Count > 0) { foreach (var defaultConfiguration in securityContract.DefaultConfigurations) { await securityContractDefaultConfigurationService.ApplyDefaultConfigurationDefinitionAsync(defaultConfiguration, updatedById, dryRun, securityContractDryRunResult); } } if (!dryRun) { // All successful CommitAllTransactions(); } else { var securityContractDryRunException = new SecurityContractDryRunException { ValidationErrors = securityContractDryRunResult.ValidationErrors, ValidationWarnings = securityContractDryRunResult.ValidationWarnings }; throw securityContractDryRunException; } } catch { RollbackAllTransactions(); throw; } }
public async Task ApplySecurityContractDefinitionAsync(SecurityContract securityContract, Guid updatedById) { // Start transactions to allow complete rollback in case of an error BeginAllTransactions(); try { // First apply all of the application(micro-service) definitions that present within the Security Contract. // All the components of a security contract are optional, so check for this here. if (securityContract.Applications != null && securityContract.Applications.Count > 0) { foreach (var applicationSecurityContractDefinition in securityContract.Applications) { await securityContractApplicationService.ApplyResourceServerDefinitionAsync(applicationSecurityContractDefinition, updatedById); } } // Apply any clients that may be defined within the security contract. if (securityContract.Clients != null && securityContract.Clients.Count > 0) { foreach (var clientSecurityContractDefinition in securityContract.Clients) { await clientService.ApplyClientDefinitionAsync(clientSecurityContractDefinition); } } // Apply any default configurations that may be defined within the security contract. if (securityContract.DefaultConfigurations != null && securityContract.DefaultConfigurations.Count > 0) { foreach (var defaultConfiguration in securityContract.DefaultConfigurations) { await securityContractDefaultConfigurationService.ApplyDefaultConfigurationDefinitionAsync(defaultConfiguration, updatedById); } } // All successful CommitAllTransactions(); } catch (Exception ex) { logger.Error(ex); RollbackAllTransactions(); throw; } }