From f2c64f44be82c7694fe60bddae58f9b28806abbb Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Thu, 18 Jan 2024 16:23:27 -0800 Subject: [PATCH] Misc cleanup, code review suggestions --- .../src/org/labkey/embedded/LabKeyServer.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/server/embedded/src/org/labkey/embedded/LabKeyServer.java b/server/embedded/src/org/labkey/embedded/LabKeyServer.java index 56cc83e285..d5ff140dab 100644 --- a/server/embedded/src/org/labkey/embedded/LabKeyServer.java +++ b/server/embedded/src/org/labkey/embedded/LabKeyServer.java @@ -293,7 +293,7 @@ private List getDataSourceResources(ContextProperties props, St dataSourceResource.setProperty("accessToUnderlyingConnectionAllowed", getPropValue(props.getAccessToUnderlyingConnectionAllowed(), i, ACCESS_TO_CONNECTION_ALLOWED_DEFAULT, "accessToUnderlyingConnectionAllowed")); dataSourceResource.setProperty("validationQuery", getPropValue(props.getValidationQuery(), i, VALIDATION_QUERY_DEFAULT, "validationQuery")); - // These two properties are handled different, as separate parameters + // These two properties are handled differently, as separate parameters String displayName = getPropValue(props.getDisplayName(), i, null, "displayName"); if (displayName != null) { @@ -356,6 +356,7 @@ private ContextResource getLdapResource() ldapResource.setName("ldap/ConfigFactory"); ldapResource.setAuth("Container"); ldapResource.setType(ldapProps.getType()); + ldapResource.setProperty("factory", ldapProps.getFactory()); ldapResource.setProperty("host", ldapProps.getHost()); ldapResource.setProperty("port", Integer.toString(ldapProps.getPort())); if (ldapProps.getPrincipal() != null) @@ -366,14 +367,8 @@ private ContextResource getLdapResource() { ldapResource.setProperty("credentials", ldapProps.getCredentials()); } - if (ldapProps.isUseSsl()) - { - ldapResource.setProperty("useSsl", Boolean.toString(ldapProps.isUseSsl())); - } - if (ldapProps.isUseTls()) - { - ldapResource.setProperty("useTls", Boolean.toString(ldapProps.isUseTls())); - } + ldapResource.setProperty("useSsl", Boolean.toString(ldapProps.isUseSsl())); + ldapResource.setProperty("useTls", Boolean.toString(ldapProps.isUseTls())); if (ldapProps.getSslProtocol() != null) { ldapResource.setProperty("sslProtocol", ldapProps.getSslProtocol()); @@ -459,11 +454,15 @@ private static String getExecutableJar(String currentPath) throws ConfigExceptio File currentDir = new File(currentPath); List jarsPresent = new ArrayList<>(); - for (File file: currentDir.listFiles()) + File[] files = currentDir.listFiles(); + if (files != null) { - if (file.getName().toLowerCase().endsWith(".jar")) + for (File file : files) { - jarsPresent.add(file.getName()); + if (file.getName().toLowerCase().endsWith(".jar")) + { + jarsPresent.add(file.getName()); + } } } @@ -478,15 +477,16 @@ private static String getExecutableJar(String currentPath) throws ConfigExceptio return jarsPresent.get(0); } - throw new ConfigException("Multiple jars found - " + jarsPresent.toString() + ". Must provide only one jar."); + throw new ConfigException("Multiple jars found - " + jarsPresent + ". Must provide only one jar."); } private static void extractZip(InputStream zipInputStream, String destDirectory) throws IOException { File destDir = new File(destDirectory); - if (!destDir.exists()) + //noinspection SSBasedInspection + if (!destDir.exists() && !destDir.mkdirs()) { - destDir.mkdir(); + throw new IOException("Failed to create directory " + destDir + " - please check file system permissions"); } try (ZipInputStream zipIn = new ZipInputStream(zipInputStream)) { @@ -504,7 +504,11 @@ private static void extractZip(InputStream zipInputStream, String destDirectory) { // if the entry is a directory, make the directory File dir = new File(filePath); - dir.mkdirs(); + //noinspection SSBasedInspection + if (!dir.exists() && !dir.mkdirs()) + { + throw new IOException("Failed to create directory " + dir + " - please check file system permissions"); + } } zipIn.closeEntry(); entry = zipIn.getNextEntry();