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/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 ======== 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() 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 diff --git a/src/main/java/com/glencoesoftware/ldaptool/Main.java b/src/main/java/com/glencoesoftware/ldaptool/Main.java index 33ac83f..cf4accb 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,32 +100,45 @@ private int executionStrategy(ParseResult parseResult) { if (doInit.get() && !parseResult.isUsageHelpRequested() && !parseResult.isVersionHelpRequested()) { - init(); + try { + init(); + } catch (RuntimeException re) { + throw re; + } 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", "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"); } }