From c10474fd3035fcde5e9d911e6c8a9eb4be015398 Mon Sep 17 00:00:00 2001 From: Ludy Date: Wed, 20 Aug 2025 16:35:24 +0200 Subject: [PATCH] fix(h2): refine SQL condition check for custom database flag (#4216) # Description of Changes - Refactored `H2SQLCondition.matches` to use `env.getProperty` with proper default values and types. - Adjusted logic to only return `false` when a custom database is enabled and datasource type is not `h2`. - Simplified environment variable handling for better readability and robustness. --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- .../proprietary/security/database/H2SQLCondition.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/database/H2SQLCondition.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/database/H2SQLCondition.java index 4e259e49b..6cb5d2bce 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/database/H2SQLCondition.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/database/H2SQLCondition.java @@ -8,16 +8,15 @@ public class H2SQLCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + var env = context.getEnvironment(); boolean enableCustomDatabase = - Boolean.parseBoolean( - context.getEnvironment() - .getProperty("system.datasource.enableCustomDatabase")); + env.getProperty("system.datasource.enableCustomDatabase", Boolean.class, false); - if (!enableCustomDatabase) { + if (enableCustomDatabase) { return false; } - String dataSourceType = context.getEnvironment().getProperty("system.datasource.type"); + String dataSourceType = env.getProperty("system.datasource.type", String.class, ""); return "h2".equalsIgnoreCase(dataSourceType); } }