From 27eefa7fb8937df3db27ffb64d0e50bae584bcae Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Thu, 11 Jan 2024 10:32:51 +0000 Subject: [PATCH 1/5] Add backslash escaping --- .../com/glencoesoftware/ldaptool/Main.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/glencoesoftware/ldaptool/Main.java b/src/main/java/com/glencoesoftware/ldaptool/Main.java index 33ac83f..edae6d8 100644 --- a/src/main/java/com/glencoesoftware/ldaptool/Main.java +++ b/src/main/java/com/glencoesoftware/ldaptool/Main.java @@ -26,8 +26,11 @@ import ome.logic.LdapImpl; import ome.system.OmeroContext; -import java.io.File; -import java.io.FileInputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; @@ -67,7 +70,7 @@ public class Main required = true, scope = ScopeType.INHERIT ) - File config; + Path config; // Non-CLI fields OmeroContext context; @@ -97,26 +100,33 @@ private int executionStrategy(ParseResult parseResult) { if (doInit.get() && !parseResult.isUsageHelpRequested() && !parseResult.isVersionHelpRequested()) { - init(); + try { + init(); + } catch (Exception e) { + throw new RuntimeException(e); + } } return new CommandLine.RunLast().execute(parseResult); } - public void init() { + public void init() throws IOException { ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(Level.toLevel(logLevel)); - log.info("Loading LDAP configuration from: {}", - config.getAbsolutePath()); - try (FileInputStream v = new FileInputStream(config)) { - Properties properties = System.getProperties(); - properties.load(v); - log.info("Properties: {}", properties); - System.setProperties(properties); - } catch (Exception e) { - throw new RuntimeException(e); - } + log.info("Loading LDAP configuration from: {}", config); + String asString = Files.readString(config); + // Configuration will come out of `omero config get` or similar without + // backslash escaping. If configuration is sourced this way it is + // unlikely to be escaped correctly, a Java properties requirement, + // before being passed in so we will perform the escaping ourselves. + asString = asString.replace("\\", "\\\\"); + ByteArrayInputStream v = new ByteArrayInputStream( + asString.getBytes(StandardCharsets.UTF_8)); + Properties properties = System.getProperties(); + properties.load(v); + log.info("Properties: {}", properties); + System.setProperties(properties); context = new OmeroContext(new String[]{ "classpath:ome/config.xml", From dbfc35e8e52224c15e43cb89e67feb062116fc48 Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Thu, 11 Jan 2024 10:39:46 +0000 Subject: [PATCH 2/5] Check and error if `omero.ldap.config` is not set correctly --- src/main/java/com/glencoesoftware/ldaptool/Main.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/glencoesoftware/ldaptool/Main.java b/src/main/java/com/glencoesoftware/ldaptool/Main.java index edae6d8..cf4accb 100644 --- a/src/main/java/com/glencoesoftware/ldaptool/Main.java +++ b/src/main/java/com/glencoesoftware/ldaptool/Main.java @@ -102,6 +102,8 @@ private int executionStrategy(ParseResult parseResult) { && !parseResult.isVersionHelpRequested()) { try { init(); + } catch (RuntimeException re) { + throw re; } catch (Exception e) { throw new RuntimeException(e); } @@ -133,6 +135,10 @@ public void init() throws IOException { "classpath:ome/services/datalayer.xml", "classpath*:beanRefContext.xml"}); ldapImpl = (LdapImpl) context.getBean("internal-ome.api.ILdap"); + if (!ldapImpl.getSetting()) { + throw new RuntimeException( + "LDAP is not enabled, is `omero.ldap.config` set?"); + } ldapTemplate = (LdapTemplate) context.getBean("ldapTemplate"); } } From c1ae7f72c20cb95953a1edf780fc62f3e24d9d22 Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Thu, 11 Jan 2024 10:49:13 +0000 Subject: [PATCH 3/5] Drop Java 8, add Java 17 --- .github/workflows/build.yml | 2 +- build.gradle | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 371af10..4ad5b9c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - java: [8, 11] + java: [11, 17] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: diff --git a/build.gradle b/build.gradle index 1ffc306..3a2ec16 100644 --- a/build.gradle +++ b/build.gradle @@ -9,8 +9,9 @@ version = '0.3.1-SNAPSHOT' mainClassName = 'com.glencoesoftware.ldaptool.Main' -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +compileJava { + options.release = 11 +} repositories { mavenCentral() From d09453e74ef40663d09fa4e7ded61473996b3cf1 Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Thu, 11 Jan 2024 11:14:36 +0000 Subject: [PATCH 4/5] Upgrade to Gradle 7.6.3 for Java 17 support --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a56324..068cdb2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 70c945ebec9e424add81852892ea52ed791afb2c Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Thu, 11 Jan 2024 11:27:52 +0000 Subject: [PATCH 5/5] Update documentation to reflect Java 11 requirement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 476dcbc..010ac88 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Requirements ============ * OMERO 5.6.x+ -* Java 8+ +* Java 11+ Workflow ========